Characteristics of python list
The crucial characteristics of Python List are listed below-
- Lists can contain any arbitrary objects.
- Lists are ordered.
- Lists elements can be accessed by index.
- Lists are mutable.
- Lists can be nested to arbitrary depth.
1. Lists can contain any arbitrary objects
A list can contain the same types of values
list = [ 10, 20, 12, 9 ]
print( list )
Output
[ 10, 20, 12, 9 ]
list = [ ‘Ajay’ , ‘Raju’, ‘Vipin’]
print( list )
Output
[ ‘Ajay’ , ‘Raju’, ‘Vipin’]
Or it can contain mixed values
list = [10, ‘Ajay’, 20 ]
print( list )
Output
[10, ‘Ajay’, 20 ]
2. Lists are ordered
a = [5, 7, 1, 15]
print(a)
Output
[5, 7, 1, 15]
a =5, 7, 1, 15] [5, 7, 1, 15]
list = [10, 20, 30, 40, 50 ]
if we want to get element 30 then we will write-
print( list [2] )
output
30
3. Lists elements can be accessed by index
list = [10, 20, 30, 40, 50 ]
if we want to get element 30 then we will write-
print( list [2] )
output
30
list = [10, 20, 30, 40, 50 ]
if we want to get element 20 then
print( list[-4 ])
output
20
4. List are mutable
list = [10, 20, 30, 40, 50 ]
if we want to change the fourth element then
list[3] = 7
print(list)
Output
[10, 20, 30, 7, 50 ]
5. Lists can be nested to arbitrary depth
a = [ 1, 2, [ 10, 20, 30, [100, 500 ], 40, 50 ], 3, 4, 5 ]
print( a )
Output
[ 1, 2, [ 10, 20, 30, [100, 500 ], 40, 50 ], 3, 4, 5 ]
What is Python List
How to Create Python List
How to Traverse a list in Python
How to Manipulate list in Python
How to Modify multiple elements in Python list
Slicing in Python List
Built in function of Python List