Skip to content

Commit 557172c

Browse files
authored
Create List_Methods
1 parent dc47b95 commit 557172c

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

List_Methods

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
L = ['yellow', 'red', 'blue', 'green', 'black']
2+
3+
#Slicing
4+
5+
print L[0]
6+
print l[0:1]
7+
print L[1:3]
8+
print L[-1]
9+
print[1:-1]
10+
11+
#Length
12+
print len(L) # Number of items in List
13+
14+
#Sort
15+
M = sorted (L)
16+
print (M)
17+
18+
#Append
19+
L.append('pink')
20+
print (L)
21+
22+
#Insert
23+
L.insert(0, "white")
24+
25+
#Extend
26+
L2 = ["a","b","f"]
27+
L.extend(L2)
28+
29+
#Remove
30+
L.remove("f")
31+
32+
#Delete
33+
Del.L[0]
34+
35+
#pop
36+
L.pop()
37+
L.pop(1)
38+
39+
#reverse
40+
L.reverse()
41+
42+
#count
43+
L.count(1)
44+
L.count('a')
45+
46+
#in
47+
if 'red' in L:
48+
print ("list contains red")
49+
50+
else:
51+
print("list doesnt contain red")
52+
53+
#for
54+
for item in L:
55+
print (item)
56+
57+
L = ['red', 'blue', 'green']
58+
for col in L:
59+
print (col)
60+

0 commit comments

Comments
 (0)