+ 1

Can someone please explain this python code?

a,b,*c=['1','2','3','4'] print(*c) what is *c here and why does it prints only '3 4' as output and not whole list?

2nd Jan 2021, 6:13 PM
Lambda
Lambda - avatar
4 Answers
+ 1
a, b, *c=['1','2','3','4'] a is assigned '1' b is assigned '2' c then "scoops up" everything else as a list. print(*c) c is unpacked and printed. edit..."as a list" not "as a tuple".
2nd Jan 2021, 6:28 PM
rodwynnejones
rodwynnejones - avatar
+ 4
Here a = '1' , b = '2', c = ['3', '4'] This is called multiple assignment or Unpacking https://stackabuse.com/unpacking-in-JUMP_LINK__&&__python__&&__JUMP_LINK-beyond-parallel-assignment/
2nd Jan 2021, 6:25 PM
Deekshant
Deekshant - avatar
+ 2
'1' and '2' are reserved for the a and b variables.The rest of elements are for c variable.
2nd Jan 2021, 6:22 PM
HBhZ_C
HBhZ_C - avatar
+ 2
Thanks!
2nd Jan 2021, 6:27 PM
Lambda
Lambda - avatar