# Lesson of List
#List is a collection which is ordered and can be changed. Lists are specified in square brackets.
mylist=["iPhone","Pixel","Samsung"]
print(mylist) # prints ['iPhone', 'Pixel', 'Samsung']
list1=[1,4,"Gitam",6,"college"]
list2=[] # creates an empty list
list3=list((1,2,3))
print(list1)
print(list2)
print(list3)
mylist=["iPhone","Pixel","Samsung"]
print(mylist) # prints ['iPhone', 'Pixel', 'Samsung']
Step 1
Step 2
Step 3
1. Repetition
The repetition operator enables the list elements to be repeated multiple times.
# repetition of list
# declaring the list
list1 = [12, 14, 16, 18, 20]
# repetition operator *
L = list1 * 2
print(L)
2. Concatenation
It concatenates the list mentioned on either side of the operator.
# concatenation of two lists
# declaring the lists
list1 = [12, 14, 16, 18, 20]
list2 = [9, 10, 32, 54, 86]
# concatenation operator +
L = list1 + list2
print(L)
3. Length
It is used to get the length of the list
# size of the list
# declaring the list
list1 = [12, 14, 16, 18, 20, 23, 27, 39, 40]
# finding length of the list
len(list1)
The for loop is used to iterate over the list elements.
# iteration of the list
# declaring the list
list1 = [12, 14, 16, 39, 40]
# iterating
for i in list1:
print(i)
It returns true if a particular item exists in a particular list otherwise false.
# membership of the list
# declaring the list
list1 = [100, 200, 300, 400, 500]
# true will be printed if value exists
# and false if not
print(600 in list1)
print(700 in list1)
print(1040 in list1)
print(300 in list1)
print(100 in list1)
print(500 in list1)