Print Lists In Python

Python provides a list structure in order to store multiple items in a single variable. These variables can be different types like string, integer, object, etc. A list can be printed by using different ways in Python. Printing a list means putting item values into the standard output like a terminal, web page, or file. The list is very similar to the array in other programming languages and printing the list operation also called a printing array in Python.

Print List with for Loop

The most popular and traditional way to print a list is using the for loop. The for loop is used to iterate over all elements of the list items and these items are printed by using the print() method.

countries = ["usa","germany","turkey","spain"]

for item in countries:

Print List with print() Method

Another easy way to print a list is using the print() method which is very useful. Also, the * operator is used to export all items of the list. All printed items are separated with spaces.

countries = ["usa","germany","turkey","spain"]


Alternatively we can specify different separator than space. Command can be used as separator for the printed items.

countries = ["usa","germany","turkey","spain"]

print(*a,sep=", ")

Print List with join() Method

The join() method is used to put multiple items into a single string by joning them. The string type provides the join() method which accepts list as parameter and all items are put together by using string value as separator.

countries = ["usa","germany","turkey","spain"]

print(' '.join(countries))

Leave a Comment