python program to print elements in a list; Through this tutorial, i am going to show you how to print elements in a list in python.
Python program to print list elements in different ways
- 1: Python Print List Elements using For Loop
- 2: Python program to print list without using loop
- 3: Python program to print list using map
1: Python Print List Elements using For Loop
# Python program to print list using for loop # define a list a = [1, 2, 3, 4, 5] # printing the list using loop for x in range(len(a)): print(a[x])
After executing the program, the output will be:
1 2 3 4 5
2: Python program to print list without using loop
# Python program to print list without using loop a = [1, 2, 3, 4, 5] # printing the list using * operator separated # by space print(*a) # printing the list using * and sep operator print("printing lists separated by commas") print(*a, sep = ", ") # print in new line print("printing lists in new line") print(*a, sep = "\n")
After executing the program, the output will be:
1 2 3 4 5
3: Python program to print list using map
# Python program to print list using map a = [1, 2, 3, 4, 5] print(' '.join(map(str, a))) print("in new line") print('\n'.join(map(str, a)))
After executing the program, the output will be:
1 2 3 4 5 in new line 1 2 3 4 5
Recommended Python Tutorials
Recommended:-Python program for Zip, Zap and Zoom game
Recommended:-Python Program to Swap Two Numbers
Recommended:-Python Program to Find n-th term of Fibonacci Series
Recommended:-Python Program For Calculator
Recommended:-Python Program to Find Strong Number
Recommended:-Python Program to Convert cm to Feet and Inches
Recommended:-How to Reverse a List in Python
Recommended:-Python Program to Convert Celsius to Fahrenheit
Recommended:-Python Program to Find Standard Deviation
Recommended:-Python Program to Check Perfect Number
Recommended:-Python Program to Display Calendar
Recommended:-Python Program to Print Alphabets from A to Z
Recommended:-Python Program to Find Roots of Quadratic Equation
Recommended:-Python Program to Find the Variance