Please explain this question in the challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Please explain this question in the challenge

https://www.sololearn.com/post/927158/?ref=app

9th Feb 2021, 5:21 AM
∆BH∆Y
∆BH∆Y - avatar
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.
9th Feb 2021, 7:31 AM
noteve
noteve - avatar
+ 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.
9th Feb 2021, 7:48 AM
noteve
noteve - avatar
+ 6
∆BH∆Y Try these examples, and try to experiment. https://code.sololearn.com/cz9vKTgRBTXL/?ref=app
9th Feb 2021, 7:55 AM
noteve
noteve - avatar
+ 4
Thank you
9th Feb 2021, 7:53 AM
∆BH∆Y
∆BH∆Y - avatar
+ 3
Cyan but the values are assigned respectively, why then d = 3 and not c = 3
9th Feb 2021, 7:43 AM
∆BH∆Y
∆BH∆Y - avatar
+ 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 "*"
10th Feb 2021, 5:44 PM
Luke Edingboro
Luke Edingboro - avatar
0
what is ansere
21st Feb 2021, 7:12 PM
Abida Yasmin
Abida Yasmin - avatar