New course! Every coder should learn Generative AI!
Try a free lesson+ 4
Please explain this question in the challenge
7 Answers
+ 10
a, b, *c, d = 1, 2, 3
*c indicates an optional and multiple values.
So first, assign values to the non optional variables.
a = 1
b = 2
d = 3
Since there are no values remaining to be assigned to c, it will be an empty list.
+ 6
That is because 'd' is not an optional variable, i.e. requires value, therefore the program will prioritize it and assign a value to it first even if it is at last position.
And since *c is optional, the program wont complain, rather it will just leave it as no value or (empty list).
Try to experiment further regarding unpacking with *variable.
+ 6
∆BH∆Y Try these examples, and try to experiment.
https://code.sololearn.com/cz9vKTgRBTXL/?ref=app
+ 4
Thank you
+ 3
Cyan but the values are assigned respectively, why then d = 3 and not c = 3
+ 1
Because the standard variables are processed first, and the filler variables (in this case *c) cleans up what's left.
Initially:
Any variable before the *c will take values from the starting values in order.
Then:
Any variable after the *c will take from the last values. The last variable takes from the last value, the second from last var takes from the second from last var and so on.
Last:
Any remaining variables will be packed into the *c variable.
As there are no values left after the 'then' part, var will be empty. The values are assigned respectively, but are also respective of the position of "*"
0
what is ansere