In this Python program, we will learn how to print the elements of the list. In this program, we print the element of the integer list and the element of the string list.
Here is the source code of the program to print the elements of the list.
# Python Program to Print an Integer List
lst = [52, 20, 65, 90, 20, 15]
print("Element in this List are: ")
print(lst)
Element in this List are:
[52, 20, 65, 90, 20, 15]
# Python Program to print the Elements with their Index from a List
lst = [52, 20, 65, 90, 20, 15]
print("\nElement in this List are: ")
for i in range(len(lst)):
print("Element at Position %d = %d" %(i, lst[i]))
Element in this List are:
Element at Position 0 = 52
Element at Position 1 = 20
Element at Position 2 = 65
Element at Position 3 = 90
Element at Position 4 = 20
Element at Position 5 = 15
# Python Program to print the String List
Fruits = ['Apple', 'Orange', 'Grape', 'Banana', 'Strawberry']
print("Element in this List are: ")
print(Fruits)
Element in this List are:
['Apple', 'Orange', 'Grape', 'Banana', 'Strawberry']
# Python Program to print the String Elements from a List
Fruits = ['Apple', 'Orange', 'Grape', 'Banana']
print("Element in this List are : ")
for fruit in Fruits:
print(fruit)
Element in this List are:
['Apple', 'Orange', 'Grape', 'Banana', 'Strawberry']
Element in this List are :
Apple
Orange
Grape
Banana
Comments