;

Python Program to Print the Elements in a List


Tutorialsrack 02/05/2020 Python

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.

Program 1: Python Program to Print an Integer List 

Python Program to Print an Integer List 
# Python Program to Print an Integer List 

lst = [52, 20, 65, 90, 20, 15]

print("Element in this List are: ")
print(lst)

Output

Element in this List are: 

[52, 20, 65, 90, 20, 15]

Program 2: Python Program to print the Elements with their Index from a List

Python Program to print the Elements with their Index from a List
# 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]))
Output

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

Program 3: Python Program to print the String List

Python Program to print the String List
# Python Program to print the String List

Fruits = ['Apple', 'Orange', 'Grape', 'Banana', 'Strawberry']

print("Element in this List are: ")
print(Fruits)
Output

Element in this List are: 

['Apple', 'Orange', 'Grape', 'Banana', 'Strawberry']

Program 4: Python Program to print the String Elements from a List

Python Program to print the String Elements from a List
# 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)    
Output

Element in this List are: 

['Apple', 'Orange', 'Grape', 'Banana', 'Strawberry']

Element in this List are : 

Apple

Orange

Grape

Banana


Related Posts



Comments

Recent Posts
Tags