Page 133 - Code_GPT_Class_8
P. 133
An empty list is a list that does not contain the items in it. The example of the empty list is given as follows:
To create empty list:
List1 = [ ]
Some other examples of the list are given as follows:
To create list of 4 integer elements: L1 = [1, 2, 3, 4]
To create list of characters: L1 = [’a’, ’b’, ’c’]
To create list of 3 strings: L1 = [“Nikhil”, “Dikshant”, “Jatin”]
To create list of integer and float numbers: L1 = [1, 1.5, 2.5, 7]
To create list with mixed data types: L1 = [7, “Hello”, 3.14]
Program 1: To print the different types of lists
Program1.py
File Edit Format Run Options Window Help
new_list1=[5, 6, 7, 8] #Homogeneous data elements
print(new_list1)
new_list2=[5, "Orange", 15.5] #Heterogeneous data elements
print(new_list2)
On running the above program, you will get the following output:
Output
[5, 6, 7, 8]
[5, 'Orange', 15.5]
Nested List
A list that contains another list in it, is called a nested list. The example of the nested list is given as follows:
To create nested list: L1 = [’Orange’, 2.0, 5, [10,20]]
Program 2: To print the nested list
Program2.py
File Edit Format Run Options Window Help
L1 = ['Orange', 2.0, 5, [10,20]]
Output
print(L1) ['Orange', 2.0, 5, [10, 20]]
List in Python 131

