Contents
Print a List
To print a list in Python, we can pass the list as argument to print() function. The print() function converts the list into a string, and prints it to console output.
If we need to print elements of the list one by one, we can use a loop statement like while or for loop, iterate over the elements of the list, and print them to console output.
Print list to console output
In the following program, we take a list of fruit names, and print this list using print statement.
Python Program
#initialise a list
myList = ['apple', 'banana', 'cherry']
#print list to console output
print(myList)
Run Output
['apple', 'banana', 'cherry']
Print list, element by element, to console output
In the following program, we take a list of fruit names, and print this list, element by element, using a for loop and print statement.
Python Program
#initialise a list
myList = ['apple', 'banana', 'cherry']
#print list to console output element by element
for element in myList :
print(element)
Run Output
apple
banana
cherry
Summary
In this tutorial of Python Examples, we learned how to print a given list to console output, using print() function.
Related Tutorials
- Python Program to Find Largest Number in a List
- Python – Convert List to Dictionary
- Python – How to Create an Empty List?
- How to Reverse Python List?
- How to Get List of all Files in Directory and Sub-directories?
- Python – Count the items with a specific value in the List
- Python – Get Index or Position of Item in List
- Python Program to Find Duplicate Items of a List
- Python Program to Find Smallest Number in List
- Python List with First N Elements