How can I format a list to print each element on a separate line in python?

user1825241 picture user1825241 · Nov 18, 2012 · Viewed 146.5k times · Source

How can I format a list to print each element on a separate line? For example I have:

mylist = ['10', '12', '14']

and I wish to format the list so it prints like this:

10
12
14

so the \n, brackets, commas and '' is removed and each element is printed on a separate line Thanks

Answer

user648852 picture user648852 · Nov 18, 2012

Embrace the future! Just to be complete, you can also do this the Python 3k way by using the print function:

from __future__ import print_function  # Py 2.6+; In Py 3k not needed

mylist = ['10', 12, '14']    # Note that 12 is an int

print(*mylist,sep='\n')

Prints:

10
12
14

Eventually, print as Python statement will go away... Might as well start to get used to it.