How to print Lists in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about How to print Lists in Python. By using some methods you can print a list in python. Here i am giving you some methods which will help you print a list in python. So without wasting your time lets learn about of this.

How to print Lists in Python

Advertisements
  1. Print Lists in Python

    to print Lists in Python just Use * operator. The * operator used to print a list in python. By using * operator you can print each element in a line and with the space between two elements. Here first of all make a list and then use * operator with a list and print it. It will give you the list of elements Lets learn this by given below method. I hope you guys like it. mylist = [10,20,30,40,50] print(mylist) print("After using the * operator: ") print(*mylist) Output : [10, 20, 30, 40, 50] After using the * operator: 10 20 30 40 50

  2. How to print Lists in Python

    to print Lists in Python just Use map(). By using map() function you can print a list in python. By using it you can print a list in a sequence without using any type of loop. Thus this method is also very important. It will print each elements of a list in a new line by using\n character. You have to use here map() and join() function. Lets learn this by given example: mylist = [10,20,30,40,50] print(mylist) print("After using the map(): ") print('\n'.join(map(str, mylist))) Output : [10, 20, 30, 40, 50] After using the map(): 10 20 30 40 50

Method 1: Use * operator

Advertisements

The * operator used to print a list in python. By using * operator you can print each element in a line and with the space between two elements. Here first of all make a list and then use * operator with a list and print it. It will give you the list of elements Lets learn this by given below method. I hope you guys like it.

mylist = [10,20,30,40,50]
print(mylist)
print("After using the * operator: ")
print(*mylist)

Output :

[10, 20, 30, 40, 50]
After using the * operator:
10 20 30 40 50

Method 2: Use map()

Advertisements

By using map() function you can print a list in python. By using it you can print a list in a sequence without using any type of loop. Thus this method is also very important. It will print each elements of a list in a new line by using\n character. You have to use here map() and join() function. Lets learn this by given example:

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

Output :

[10, 20, 30, 40, 50]
After using the map():
10
20
30
40
50

Method 3: Use for loop

Advertisements

By using for loop you can print a list in python. This is the most easy way to print a list in python.

mylist = [10,20,30,40,50]
print("After using for loop:")
for x in mylist:
    print(x)

Output :

After using for loop:
10
20
30
40
50

Method 4: Use join()

Advertisements

By using join() you can print a list in python. Here if you have the list of the strings than this method will help you. Lets learn this how it works. I hope you guys like it

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

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment