Here, we will figure out how to proclaim a rundown and how to print the rundown components in Python?
Proclaim a rundown and print the components/objects of the rundown in Python.
Program:
# declaring list with integer elements
list1 = [10, 20, 30, 40, 50]
# printing list1
print "List element are: ", list1
# printing elements of list1 by index
print "Element @ 0 index:", list1[0]
print "Element @ 1 index:", list1[1]
print "Element @ 2 index:", list1[2]
print "Element @ 3 index:", list1[3]
print "Element @ 4 index:", list1[4]
# declaring list with string elements
list2 = ["Chandigarh", "Chattisgarh", "Bilaspur", "Dehli"]
# printing list2
print "List elements are: ", list2
#printing elements of list2 by index
print "Element @ 0 index:",list2 [0]
print "Element @ 1 index:",list2 [1]
print "Element @ 2 index:",list2 [2]
print "Element @ 3 index:",list2 [3]
print " " # prints new line
# declaring list with mixed elements
list3 = ["Kishan Kaushik", 19, "Bilaspur", 888607812]
#printing list3
print "List elements are: ", list3
# printing elements of list3 by index
print "Element @ 0 index (Name) :", list3[0]
print "Element @ 1 index (Age ) :", list3[1]
print "Element @ 2 index (City) :", list3[2]
print "Element @ 3 index (Mob.) :", list3[3]
print "" # prints new line
Output:
List element are: [10, 20, 30, 40, 50]
Element @ 0 index: 10
Element @ 1 index: 20
Element @ 2 index: 30
Element @ 3 index: 40
Element @ 4 index: 50
List elements are: ['Chandigarh', 'Chattisgarh', 'Bilaspur', 'Dehli']
Element @ 0 index: Chandigarh
Element @ 1 index: Chattisgarh
Element @ 2 index: Bilaspur
Element @ 3 index: Dehli
List elements are: ['Amit Shukla', 21, 'New Delhi', 9876543210]
Element @ 0 index (Name) : Kishan Kaushik
Element @ 1 index (Age ) : 19
Element @ 2 index (City) : Bilaspur
Element @ 3 index (Mob.) : 888607812