0

The asterisk in *c in Python?

What does * mean in a,b,*c,d = 1,2,3 print(c) #output: [] And why does it give this output?

23rd Jun 2019, 10:31 AM
Brave Tea
Brave Tea - avatar
2 Answers
+ 4
Say you had this line instead: a,b,*c,d = 1,2,3,4,5,6,7,8,9,10 a and b take the first two numbers (because a and b appear first), so a would be assigned the value 1, and b would be 2. d being the last in the list, takes the last number, so d is now 10. *c means that c is assigned everything else in between. So c would now be [3,4,5,6,7,8,9]. In your example, there wasn't anything left to be assigned to c, so it was an empty set.
23rd Jun 2019, 10:56 AM
Russ
Russ - avatar
+ 1
thanks Russ ! that is a great explanation!
23rd Jun 2019, 11:07 AM
Brave Tea
Brave Tea - avatar