-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListDemo.py
More file actions
121 lines (66 loc) · 1.5 KB
/
Copy pathListDemo.py
File metadata and controls
121 lines (66 loc) · 1.5 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# simple list creation
# example 1
list1 = [10,20,30,40]
print(list1)
print(list1[0])
print(list1[-2]) # negative index
# example 2
list2 = [[ 'nitesh', 'kumar'],[10,20,30,40]]
print(list2)
print(list2[0])
print(list2[0][1])
# example 3
data = 'The ' + list2[0][-1] + ' is a genius ' + str(list2[1][-2])
print(data)
# example 4 slicing ([:])
list3 = ['cat', 'dog', 'elephant']
print(list3[1:2])
# Note - index -> single value & slice -> list of values
# example 5 - changing list items
spam = 'Hello'
spam = [10, 20, 30]
spam[1] = 'Hello'
print(spam)
spam[1:3] = ['CAT', 'DOG', 'MOUSE']
print(spam)
# example 6 - slice shortcuts
spam1 = ['CAT', 'DOG', 'MOUSE', 'ELE']
print(spam1[:2])
print(spam1[1:])
# example 7 - del
spam1 = ['CAT', 'DOG', 'MOUSE', 'ELE']
del spam1[2]
print(spam1)
#print(len[1,2,3])
print([1,2,3] + [4,5,6])
'hello' * 3
[1,2,3] * 3
list('Hello')
# in or not in operators
print('howdy' in ['hello','hi','howdy'])
print('howdy' not in ['hello','hi','howdy'])
# for loop
for i in range(4):
print(i)
range(4)
range(0,4)
list(range(0,100,2))
#for i in range(len(somelist))
supplies = ['pens','staplers','flame-throwers','binders']
for i in range(len(supplies)):
print('Index' + str(i) +'in supplies is:'+supplies[i])
# multilpe asssignemnt trick
cat = ['fat', 'orange','loud']
size,color,desp = cat
print(size)
print(color)
print(desp)
a = 'AAA'
b = 'BBB'
a,b = b,a
print(a)
print(b)
# augmented assignment operators
spam = 42
spam = spam + 1
spam +=1