1myfavouritefoods = ["Pizza", "burgers" , "chocolate"]
2print(myfavouritefoods[1])
3#or
4print(myfavouritefoods)
1#list is data structure
2#used to store different types of data at same place
3list = ['this is str', 12, 12.2, True]
1myList = ["Test", 419]
2myList.append(10)
3myList.append("my code")
4print(myList)
1list = [1, 2, 3, 4, 5, 6]
2print(list)
3# It will assign value to the value to second index
4list[2] = 10
5print(list)
6# Adding multiple element
7list[1:3] = [89, 78]
8print(list)
9# It will add value at the end of the list
10list[-1] = 25
11print(list)
1the usage of list is to store multiple meaningful items into a single variable(string)
2using square bracket
3
4#define a list
5list = []
6
7items of a list are ordered, mutable and allow duplicate values unlike set
1list = [1, 2, 3, 4, 5, 6, 7, 9, 10]
2
3print("Original list", list)
4
5list[4] = 99
6
7print("Updated 1", list)
8
9# del is to delete
10
11del list[4]
12
13print("Updated 2", list)
14
15list.append(12)
16
17print("Updated 3", list)
18
19list.remove(3)
20
21print("Updated 4", list)
22
23list.pop()
24
25print("Updated 5", list)
26
27list.insert(0, 9)
28# first index is the index value where u wanna put and second is what the value is
29
30print("Updated 6", list)
31
32list.insert(0, 99)
33
34print("Updated 7", list)
35
36# How to add a list into another list
37
38second_list = [8, 9, 10]
39list[3] = second_list
40print("List after adding a new list into an exiting list", list)
41
42# How to find the mode
43
44print("Counting the number of appearances", list.count(9))
45
46
47lis = [1, 4, 6, 1, 5]
48print("Number 1 is in", lis.index(1))
49
50print("Get lenght of the list", len(list))
51
52list1 = [1, 2, 3, 4, 5, 6, 7]
53list2 = [8, 9, 10, 11, 12, 13, 14]
54
55print("Join two lists ", list1 + list2)
56
57print("Repeat the element in the list", "\nHello Sneh\n" *10)
58
59