Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

* before iterable inside a print() in Python [duplicate]

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?

like image 294
flpn Avatar asked Oct 28 '25 16:10

flpn


1 Answers

The * is used to unpack argument lists when calling a function. In this case it unpacks your list of names.

like image 55
Cary Shindell Avatar answered Oct 30 '25 07:10

Cary Shindell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!