close

How to Print Lists in Python

Hello guys. how are you? I hope you all fine. List is the data structure that stores mutable sequence of data values into it. and its very important and very easy to use and print. So now lets learn to use it and How to Print Lists in Python. Here are few methods to print it. lets learn :

How to Print Lists in Python

  1. How to Print Lists in Python

    to Print Lists in Python Using ‘*’ symbol In this method you can print list by using '*' symbol. you will better understand this by example. So lets learn it through an example. mylst = ["salt","chocolate","rice",56,30] print("Elements of the List:") print(*mylst, sep = "\n") Output : Elements of the List: salt chocolate rice 56 30 Thus you can print a list.

  2. Print Lists in Python

    to Print Lists in Python Using for loop You can print a list by using for loop. Its very easy to use. lets learn it through an example:mylist = ["salt","chocolate","rice",56,30] for l in mylist: print(l)Output :
    salt chocolate rice 56 30

Method 1 : Using ‘*’ symbol

In this method you can print list by using ‘*’ symbol. you will better understand this by example. So lets learn it through an example.

mylst = ["salt","chocolate","rice",56,30] 
print("Elements of the List:")
print(*mylst, sep  = "\n") 

Output :

Elements of the List:
salt
chocolate
rice
56
30

Thus you can print a list.

Method 2 : Using for loop

You can print a list by using for loop. Its very easy to use. lets learn it through an example:

mylist = ["salt","chocolate","rice",56,30]
for l in mylist:
    print(l)

Output :

salt
chocolate
rice
56
30

Method 3 : Using join()

You can print a list by using join().lets learn it through n example.

myList = ["salt","chocolate","rice"] 
print(' '.join(myList)) 

Output :

salt chocolate rice

Thus you can easily print list by using this method

Method 4 : Using map()

You can print a list by using map().lets learn it through n example:

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

Output :

1 2 3 4 5

Thus its also very easy method for print a list in python. I hope these all the methods help you to print the list in python.

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment