Python List Data Type
If we want to represent a group of values as a single entity where insertion order
required to preserve and duplicates are allowed then we should go for list data
type.
1) Insertion Order is preserved
2) Heterogeneous Objects are allowed
3) Duplicates are allowed
4) Growable in nature
5) Values should be enclosed within square brackets.
Eg:
list=[10,10.5,'durga',True,10]
print(list) # [10,10.5,'durga',True,10]
Eg:
list=[10,20,30,40]
>>> list[0]
10
>>> list[-1]
40
>>> list[1:3]
[20, 30]
>>> list[0]=100
>>> for i in list:print(i)
100
20
30
40
list is growable in nature. i.e based on our requirement we can increase or decrease the
size.
>>> list=[10,20,30]
>>> list.append("durga")
>>> list
[10, 20, 30, 'durga']
>>> list.remove(20)
>>> list
[10, 30, 'durga']
>>> list2=list*2
>>> list2
[10, 30, 'durga', 10, 30, 'durga']
Note: An ordered, mutable, heterogenous collection of elements is nothing but a list,
where duplicates are also allowed.