close

How to print Lists in Python

List is a built in data types which is store the multiple elements in it. In this tutorial we will learn about How to print Lists in Python. There are so many different methods to print a list in python> So without wasting your time lets learn about of this by given methods.

How to print Lists in Python

There are so many methods to print a list in python. Here are some methods which will help you

  1. print Lists in Python

    to print Lists in Python just Use * operator.* operator is used to print the elements of a list in python. It is most common n widely used method and also very simple and easy to use. list = [10,20,30,40,50] print(list) print(*list)
    Output : [10, 20, 30, 40, 50] 10 20 30 40 50 By using sep= you can get the each elements in new line> here is the example of it. Lets see this: list = [10,20,30,40,50] print(list) print(*list) print(*list, sep='\n') Output :
    [10, 20, 30, 40, 50] 10 20 30 40 50 10 20 30 40 50

  2. How to print Lists in Python

    to print Lists in Python just Use map(). By using map() and join() function you can print a list in python. and with this if you use \n character than it will give you each element in new line. Lets learn this method by given below example.
    mylist = [10,20,30,40,50] print(mylist) print('\n'.join(map(str, mylist))) Output : [10, 20, 30, 40, 50] 10 20 30 40 50

Method 1: Use * operator

* operator is used to print the elements of a list in python. It is most common n widely used method and also very simple and easy to use.

list = [10,20,30,40,50]
print(list)
print(*list)

Output :

[10, 20, 30, 40, 50]
10 20 30 40 50

By using sep= you can get the each elements in new line> here is the example of it. Lets see this:

list = [10,20,30,40,50]
print(list)
print(*list)
print(*list, sep='\n')

Output :

[10, 20, 30, 40, 50]
10 20 30 40 50
10
20
30
40
50

Thus if you want to get each element in new line than use this.

Method 2: Use map()

By using map() and join() function you can print a list in python. and with this if you use \n character than it will give you each element in new line. Lets learn this method by given below example.

mylist = [10,20,30,40,50]
print(mylist) 
print('\n'.join(map(str, mylist)))

Output :

[10, 20, 30, 40, 50]
10
20
30
40
50

Method 3: Use for loop

For loop is also used for print a list in python. And by using for loop you can get each element in new line so this is the benefit of this method. It is very simple and easy to use as you can see in below example. So lets learn this:

mylist = ['one','two','three','four','five','six','seven']
print("After using for loop:")
for l in mylist:
    print(l)

Output :

After using for loop:
one
two
three
four
five
six
seven

Method 4: Use join()

By using join you can print a list in python. So lets learn this by givrn below example:

mylist =['one','two','three','four','five','six','seven']
print(' '.join(mylist))

Output :

one two three four five six seven

Conlusion

Hope all 6 Method Are Useful For You. Comment Below Which Method You Used To Convert String To Datetime In Python. Thank You.

Also Read

Leave a Comment