1

I want to print all element of list without any loop in python. And i got this on internet. let list = [1, 2, 3, 4, 5] and print(list). But i don't know what this '' doing here.

Ritik Kumar
  • 661
  • 5
  • 16

1 Answers1

1

printing the list using * operator separated by space

a = [1, 2, 3, 4, 5]   
print(*a) 

Output:

1 2 3 4 5

printing the list using * and sep operator

print(*a, sep = ", ") 

Output:

1, 2, 3, 4, 5

print in new line

print(*a, sep = "\n")

Output:

1

2

3

4

5
  • What this '* mean here? – Ritik Kumar Oct 13 '19 at 19:28
  • @RitikKumar I believe this will provide you with all the information you need avout splat (*) in python: https://medium.com/understand-the-python/understanding-the-asterisk-of-python-8b9daaa4a558 –  Oct 13 '19 at 20:41