How to create python list
In python a List can be created by placing all the elements inside a square bracket [ ], separated by commas.
A list can contain any number of elements and they may be of different types.
A list can contain any number of elements and they may be of different types.
We can create a list by following types-
1. A list can be created from all integer values
list1 = [ 7, 5, 15, 20 ]
print( list1 )
Output
[ 7, 5, 15, 20 ]
2. A list can be created from all string values
list2 = [ ‘Indore’, ‘Bhopal’, ‘Jabalpur’ ]
print( list2 )
Output
[ ‘Indore’, ‘Bhopal’, ‘Jabalpur’ ]
3. A list can be created from mixed values like integers, floats, and strings.
list3 = [ 10, ‘Amit’, 15.7 ]
print( list3 )
Output
[ 10, ‘Amit’, 15.7 ]
4. We can also create an empty list. A list without any element is called an empty list.
list = [ ]
print( list )
Output
[ ]
5. We can create a list by concatenation of two or more lists with the + operator.
list1 = [ 10, 20, 30 ]
list2 = [ ‘Amit’, ‘Raju’ ]
list3 = [ 3.5, 3.7 ]
list = list1 + list2 + list3
print( list )
Ouput
[ 10, 20, 30, ‘Amit’, ‘Raju’, 3.5, 3.7 ]
Important Links
What is Python List
Characteristics of 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