List are special variable which can store more than one values. You can easily store many values on a list e,g
List1 = [value1, value2, value3......]
Here, List1 is the identifier of the list which can have name according to the rules discussed in variable chapter. The values are stored inside square brackets as shown and value1,value2 etc are the values in thr list. Now we will creat an actual list,
Friends = ["Jimmy","Joan","Jenny", "joy","Jan"]
You can also use a list to store numbers or variable or other lists etc
Num = ["one",2,"three",4]
List with variables and sublists
Listinlist = [ one,2,[1,2,3],"4"]Index:
values in list are recongnized by their index or in other words a number tag is given to each member of list. The first member has index 0 and than increase by 1 for each next member.
In this list,
list =[1,2,3,4]
The index of 1 is 0, that of two is 1 and for 3 it is 2 and so on.Printing list of its member:
You can print the whole list by using print method e.g to print a list called L1
L1 = [0,1,2,3,"four"]
print(L1)
>>>>>>[0,1,2,3,"four"]
You can also prina
s hyt a specific member of a list by following way
print(L1[0])
print(L1[1])
>>>>>>0 1
Here, we used the name of list in print method. The name of list is followed by member's index written square brackets
YOU ARE READING
Python Guide for Beginners
RandomThis is an easy to learn and absolutly no programming experience is required.You can start learning by opening this book right now.