-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlists.py
44 lines (28 loc) · 954 Bytes
/
lists.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
list1 = ["apple", "banana", "mangoes", "grapes"]
print(list1)
print(list1[1])
# OPERATIONs ON LISTS :
list2 = [1, 1, 1, 1, 1]
# to update an element into list (at specific position):
list2[1] = 2
print(list2)
list3 = [2, 2, 2, 2, 2]
# joining two lists :
print(list2+list3)
# to print a list multiple times :
print(list2*3)
# to check that an element is present in list or not :
names = ["hitesh", "buddhi", "hari", "giri", "anuj", "rituja"]
print("anuj" in names)
print("krishna" in names)
# LIST FUNCTIONS :
# "append()" : to append a new item to list
list1.append("Papaya")
print(list1)
# "len()" : to calculate the length of a list at end of list
print("length of list2 : ", len(list2))
# "insert()" : to insert a item at a particular position :
list1.insert(1, "orange")
print(list1)
# "index()" : return index value of an item of list :
print("position(index) of mangoes is", list1.index("mangoes"))