Loading...
Python

list Data Type

list Data Type is used to represent group of values as a single entity where insertion order required to to preserve and duplicates are allowed then list data type is used.
1. insertion order is preserved.
2. duplicates are allowed.
3. heterogeneous objects areĀ  allowed.
4. values should be enclosed within square braces.
5. Growable in nature.

Example 1:
list=[10,10.5,’Webnoid’,True,10]
print(list)#[10,10.5,’Webnoid’,True,10]

Example 2:
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 growable in nature based on our requirement size can be increased or decreased.

Example:
>>>list=[5,10,15]
>>>list.append(“Webnoid”)
>>>list
[5,10,15,’Webnoid’]
>>>list.remove(10)
>>>list
[5,15,’Webnoid’]
>>>list2=list*2
>>>list2
[5,15,’Webnoid’,5,15,’Webnoid’]

 

Leave a Reply

Your email address will not be published. Required fields are marked *