+ 2
Python
a,b,*c = [1,2,3,4] Print(c) Output: [3,4] Can someone tell what exactly is happening in this code? If I remove * it shows error, what * actually does?
5 odpowiedzi
+ 3
a, b will be get stored 1,2 respectively and remaing all will be stored in c as list data.
edit:
another example:
a, b, *c, d = [1,2,3,4,5,6,7,8,9]
print(*c) #output 3 4 5 6 7 8
# d stores 9
hope it helps.....
+ 2
c gets the remaining values so just look at the position of a and b..we know a is 1 and b is 2.. *c takes everything else after. If we move c to the middle c takes 2 and 3.. move it to the start it will take 1 and 2
+ 1
Thank you Jayakrishna🇮🇳
+ 1
Google for
Python Iterable Unpacking
good link for in depth explanation
https://stackabuse.com/unpacking-in-python-beyond-parallel-assignment/
+ 1
Thank you Bob_Li