-
Notifications
You must be signed in to change notification settings - Fork 0
/
11-python-list-methods.py
67 lines (52 loc) · 1.07 KB
/
11-python-list-methods.py
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
list1 = [1, 2, 3, 4, 5, 6]
list1.append(7)
print(list1)
list1.clear()
print(list1)
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)
print(list1)
["Hello", "World", "World"].count("Hello")
["Hello", "World", "World"].index("Hello")
["Hello", "World", "World"].index("World")
list1 = [1, 2, 3, 4, 5]
list1.insert(0, 0)
print(list1)
list1 = [5, 10, 15, 25]
list1.insert(-1, 20)
print(list1)
list1 = [5, 10, 15, 25]
list1.insert(500, 30)
print(list1)
list1 = [5, 10, 15, 25]
last_number = list1.pop()
print(last_number)
print(list1)
list1 = [5, 10, 15, 25]
list1.remove(25)
print(list1)
list1 = [5, 10, 15, 25, 25]
list1.remove(25)
print(list1)
list1 = [5, 10, 15, 25, 25]
list1.reverse()
print(list1)
list1 = ["Hello", "World"]
list1.reverse()
print(list1)
list1 = "Hello World".split()
list1.reverse()
print(list1)
list1 = list("Hello World")
print(list1)
list1.reverse()
print(list1)
reversed_string = "".join(list1)
print(reversed_string)
list1 = [5, -10, 35, 0, -65, 100]
list1.sort()
print(list1)
list1 = [5, -10, 35, 0, -65, 100]
list1.sort(reverse=True)
print(list1)