Printing Lists Line By Line in Python

In Python, printing a list line by line can be done using for loop. This is useful when we have long lists or just to make the output easier to read. Here’s how you can do it. …

Updated October 11, 2023

In Python, printing a list line by line can be done using for loop. This is useful when we have long lists or just to make the output easier to read. Here’s how you can do it.

# List of items
my_list = ["item1", "item2", "item3"]

for item in my_list:
    print(item)

In the above code, my_list is a list containing strings. We then use a for loop to iterate over each element in the list and print it out. The result would be three lines of output, one for each string in the list.

Each line is printed with an extra newline ("\n") at the end, so you can separate items visually if the list contains more than one item. If you need to print the list as a single string, use the join() method:

# Using join() to print out as single string
print('\n'.join(my_list))

This will output:

item1
item2
item3

Stay up to date on the latest in Coding Python with AI and Data Science

Intuit Mailchimp