-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.py
More file actions
67 lines (45 loc) · 840 Bytes
/
list.py
File metadata and controls
67 lines (45 loc) · 840 Bytes
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
#methods of list
a=['hello','I','am','ritu','soni','I','am','happy']
#append
a.append(3)
print(a)
a.append(34)
a.append(4.45)
a.append(len(a))
a.append(True)
print(a)
x=a.append(56) #extend and append do not return anything x is none
print(x)
#extend(iterable)
b=[1,2]
x=a.extend(b)
print(x)
a.extend(b)
print(a)
#insert
a.insert(1,0)
print(a)
#remove parameter = value that we want to remove
a.remove('hello')
a.remove(1)
a.remove(2)
#pop parameter = index that we want to pop element from.
x=a.pop(8)
print(x)
#it removes the element from the list and return it
print(a)
#a.clear() clears whole list
#index
v=a.index('ritu',2)
print(v)
#count
c=a.count(1)
print(c)
# cant sort the list with mixed values of str and int by a.sort()
a.reverse()
print(a)
c=a.copy()
print(c)
z=[1,2,3,4,5,6]
print(z[-6:-3])
print(z[:])