List:
List is a data structure in Python which is very similar to arrays in C.
The difference between array and list is that array can able to store only homogeneous elements while in list we can have non homogeneous elements also.
List is a iterative and sequential data structure.
Indexing and slicing is possible in case of list data structure.
List are denoted by [].
Duplicates values are allowed in list data structure.
Creation of empty list::
If we want to create an empty list then we can do this in two ways. These are given below:
l=[] # empty list
l=list() # empty list
Initializing the list:
l=[1,2,3,4]
print(l[2]) # 3
Printing whole list:
We can print the all elements of list in two ways.
print(l)
Using for loop
for x in l:
print(x)
Editing values of List:
l=[1,2,4]
print(l[0]) # 1
l[0]=8
print(l[0]) # 8
List is a data structure in Python which is very similar to arrays in C.
The difference between array and list is that array can able to store only homogeneous elements while in list we can have non homogeneous elements also.
List is a iterative and sequential data structure.
Indexing and slicing is possible in case of list data structure.
List are denoted by [].
Duplicates values are allowed in list data structure.
Creation of empty list::
If we want to create an empty list then we can do this in two ways. These are given below:
l=[] # empty list
l=list() # empty list
Initializing the list:
l=[1,2,3,4]
print(l[2]) # 3
Printing whole list:
We can print the all elements of list in two ways.
print(l)
Using for loop
for x in l:
print(x)
Editing values of List:
l=[1,2,4]
print(l[0]) # 1
l[0]=8
print(l[0]) # 8
Be First to Post Comment !
Post a Comment