+ 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?
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".
+ 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/
+ 2
'1' and '2' are reserved for the a and b variables.The rest of elements are for c variable.
+ 2
Thanks!