-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain6(revision).py
More file actions
81 lines (68 loc) · 2.09 KB
/
main6(revision).py
File metadata and controls
81 lines (68 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Variables casting
"""
a = int(20)
b = str(20)
c = float(20)
print(a,b,c)
"""
# many values to multiple variables
"""
x,y,z = "Kiran Rai","saurav rai","dipika tamang"
print(x,y,z)
"""
# 1 value to multiple variables
"""
x = y = z = "You"
print(y)
"""
# Unpacking the collection
# If you have a collection of values in a list, tuple etc. Python allows you to extract the variables. This is called unpacking.
# Example~:
"""
fruits = ["apple","banana","cherry"]
x,y,z = fruits
print(x)
print(y)
print(z)
"""
# Did you get this first tupples were created and then assigned to many values to multiple variables x,y,z and at last you can get the output/result by printing the variable name
# Python string slicing
# Slicing
# you can return a range of characters by using slice syntax. Specify the start index and the end index, seperated by a colon, to return a part of the string
# string slicing
# String slicing return the characters falling between indices n and m
# String at n, n+1,n+2...till m-1. The syntax is:
# Here n = size of the list
# string[Start:End:Step_value(Skipping value)]
# last index is to skip
"""
str1 = "My name is Kiran Rai"
print(len(str1))
print(str1[::-2])
"""
# list data type in python
# list is a collection of different values or different types of items.
# unlike array in c/c++/java a list is capable of storing different types of values under one roof.
# The list in the list are seperated with the comma(,) and enclosed in square bracket[].
# List provides us the facility to store multiple types of values in a single unit.
# There is two types of indexing:
# Forward indexing
# and Backward indexing
# You can update the value of any list using
# Example practice
# list = ["Kiran", "Rai", "Is", "A", "Hacker", 1 ,1 ,22,23,43,32]
# print(list[:3:-1])
# we can also put list inside list aka 2dlist,3d list and so on....
# list1 = [[1,2,3],[4,5,6],[7,8,9]]
# for sublist in list1:
# for i in sublist:
# print(i)
# print(type(list1))
# list2 = [
# [1,2,3,],[5,6,7],[8,9,0]
# ]
# list2.insert([1],[1],4)
# print(list2)
list3 = [1,2,3,4,5,7,8]
list3.clear()
print(list3)