-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathList 3 [Insert remove pop clear].py
More file actions
50 lines (33 loc) · 1.08 KB
/
List 3 [Insert remove pop clear].py
File metadata and controls
50 lines (33 loc) · 1.08 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
#;==========================================
#; Title: Python list part 3
#; Author: @AyemunHossain
#;==========================================
#........... >>>If you want to add any item to an specific index <<........#
numbers = [1,2,4,5] #....3 is missing
numbers.insert(2, 3)
print(numbers)
#Add multiple item in multiple index
numbers.insert(5,6)
numbers.insert(6,7)
numbers.insert(7,8)
numbers.insert(8,9)
numbers.insert(9,10)
print(f"Number List : {numbers}")
# .............. > let's see how to remove items form list ...........#
demo_list = [1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
#......remove method list.remove(item)
demo_list.remove(5)
print(demo_list)
demo_list.remove(6)
demo_list.remove(7)
print(demo_list)
#....pop method list.pop(index)
demo_list.pop(0)
print(demo_list)
demo_list.pop(3)
demo_list.pop(4)
print(demo_list)
#you will see here a fact when you pop index 0 then index 1 will become 0 after then things goes like that
#.......clear method ,You can delete all items with clear method
demo_list.clear()
print(f"The demo list : {demo_list}")