Python print list
In this article, we will take a look at how to print a list in python in different ways with example programs. A python list is a linear collection of elements of same or different data type.

Method 1: Print with brackets
This is the most straightforward method to print a python list. Simply pass the list to print() function and it will print the list along with brackets and comma-separated elements as shown below

# define list
names = ['A', 'B', 'C', 'D']
# print list
print(names)

This will print

[‘A’, ‘B’, ‘C’, ‘D’]

With this method, you can not change the separator between elements or formatting, it simply prints the list as it is.
Method 2: With * operator
Using * or asterisk, a python list can be printed without brackets and with elements separated by a space, semi-colon or a new line character. Example,

names = ['A', 'B', 'C', 'D']
print('List without brackets')
print(*names)
print('List with - separator')
print(*names, sep="-")
print('List with new line separator')
print(*names, sep="\n")

* is called unpacking operator and it splits list into individual elements. sep is an argument of print() function and has nothing to do with list.
Output of above code is

List without brackets
A B C D
List with – separator
A-B-C-D
List with new line separator
A
B
C
D

Method 3: Using string join()
join() method of python str class accepts an iterable(object that can be iterated) as argument and joins its elements with the string on which it is called. That is, '-'.join(iterable) will combine elements of the supplied iterable with a -.

Since list is an iterable, it can be supplied to join(). Below example combines list elements separated by a comma.

names = ['A', 'B', 'C', 'D']
print(','.join(names))

This will print list elements without brackets

A,B,C,D

To print list elements line by line, invoke join() with new line character as below

names = ['A', 'B', 'C', 'D'] 
print('\n'.join(names))

This will output

A
B
C
D

This method will only work when the elements of list are of type string.
Method 4: Using map() function
Python map() function applies a function to each element of an iterable. Its syntax is

map(func, iterable)

When str object is supplied as the first argument to map(), each element of the list is converted to a string.
map() itself returns an iterable, which can then be used with join() to create a string. Example,

nums = [1, 2, 3, 4]
m = map(str, nums)
print(' '.join(m))

This will print list with spaces. Output is

1 2 3 4

Above code can be shortened to

nums = [1, 2, 3, 4]
print(' '.join(map(str, nums)))

Method 5: Using for loop
This is the most basic method where you iterate over a list using for loop and print each element in the current iteration. Example,

names=['A', 'B', 'C', 'D']
for name in names:
    print(name)

Do not forget to hit the clap if the post was helpful.