+ 2
Python - Given a,b, *c, d = 1,2,3 how come c is equal to an empty list?
a,b, *c, d = 1,2,3 print(a) print(b) print(c) print(d) # output: 1 2 [] 3
2 Answers
+ 8
Here a ,b,d takes 1,2,3 but in *c has no value so it print empty list.
learn this lesson again
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2485/
+ 7
This is known as tuple unpacking { using * in this case }
Here first a,b,d are filled because they were memdatory variables and not filling those will result in error, and as unfilled tupple defaults to empty list so will not generate any error.
Know more about it heređ (or the link provided by SÄñtösh will also do )
https://stackabuse.com/unpacking-in-JUMP_LINK__&&__python__&&__JUMP_LINK-beyond-parallel-assignment/