0

a,b=0,1 a,b=b,a+b print(a,b)

why the output is 1 1 and not 1 2 as the new value of a is 1 at 2nd step and hence b in the second step is b=a+b, so a is 1 and b is already 1 as defined so ans. must be b=2. but it is not ! why?

27th Jul 2019, 9:45 AM
Dhyey Badheka
Dhyey Badheka - avatar
1 Answer
+ 7
The RHS statement is resolved completely before any assignment takes place. a,b = b,a+b a,b = 1,0+1 "An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right." https://docs.python.org/3/reference/simple_stmts.html
27th Jul 2019, 9:51 AM
Hatsy Rei
Hatsy Rei - avatar