list data type in Python

-->If we want to represent a group of values as a single entity where insertion order is 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.


Example

list=[10,10.5,siddu,True,10]

print(list)# [10,10.5, 'siddu', True,10]


>>>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("siddu") 

>>> list[10, 20, 30, 'siddu']

>>> list.remove(20)

>>> list#[10, 30, 'siddu']

>>> list2=list*2

>>> list2#[10, 30, 'siddu', 10, 30, 'siddu']


Note: An ordered, mutable, heterogenous collection of eleemnts is nothing but list, where duplicates also allowed.

No comments:

Post a Comment

Thank you Very Much.For Given Comment

Downloading Talliki Vandhanam List

--> Citizens can know the status of Talliki Vandhanam Click Here -->Knowing the Status of Talliki Vandhanam   --> In GSWS NBM Login...