I have a list of names and I want to print each element of the list in a different line without a for loop. So, after some research I found this example: print(*names, sep='\n')
, witch results in exactly what I want. But what does this *
character before the list name means?
Asked
Active
Viewed 279 times
3

flpn
- 1,868
- 2
- 19
- 31
-
`print(*[1,2,3])` is the same as `print(1,2,3)`. – ForceBru Jul 19 '17 at 18:41
-
See [Unpacking Argument Lists](https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists) in the official tutorial. – PM 2Ring Jul 19 '17 at 18:44
1 Answers
4
The * is used to unpack argument lists when calling a function. In this case it unpacks your list of names.

Cary Shindell
- 1,336
- 8
- 25