In this article, we will show you, How to write a Python Program to print Elements in a List with practical example. Before you start, please refer List article to understand everything about Lists.
Python Program to print Elements in a List Example 1
The print function in python will automatically print elements in a List
# Python Program to print Elements in a List a = [10, 50, 60, 80, 20, 15] print("Element in this List are : ") print(a)
OUTPUT
Python Program to print Elements in a List Example 2
This python program is same as above but this time we are using For Loop to iterate each every element in a list, and printing that element. This is very useful to alter the individual item using this index position.
# Python Program to print Elements in a List a = [10, 50, 60, 80, 20, 15] print("Element in this List are : ") for i in range(len(a)): print("Element at Position %d = %d" %(i, a[i]))
OUTPUT
Python Program to print List Elements Example 3
The print function in python also print string elements in a List
# Python Program to print Elements in a List Fruits = ['Apple', 'Orange', 'Grape', 'Banana'] print("Element in this List are : ") print(Fruits)
OUTPUT
Python Program to print List Elements Example 4
This is same as above but we used For Loop to iterate each every string element in a list.
# Python Program to print Elements in a List Fruits = ['Apple', 'Orange', 'Grape', 'Banana'] print("Element in this List are : ") for fruit in Fruits: print(fruit)
OUTPUT
Python Program to print List Elements Example 5
This program allow user to enter any integer value. This is the length of a List. Next, we used For Loop to add numbers to the list.
# Python Program to print Elements in a List NumList = [] Number = int(input("Please enter the Total Number of List Elements: ")) for i in range(1, Number + 1): value = int(input("Please enter the Value of %d Element : " %i)) NumList.append(value) for i in range(Number): print("The Element at index position %d = %d " %(i, NumList[i]))
OUTPUT