+ 3
Guys what is Perform first can you help me (a , b = b , a+b)
3 Answers
+ 3
Markus Kaleton i confused in Fibonacci Step
because if i use
a = b
b = a+b
the result is wrong
but if i use
a,b=b,a+b
the result is correct
why?đ
+ 1
because the assignments on the line are executed at the same time.
so in the a,b version
a = 1 , b = 2 prints 1
|
a = 2 , b = 3 prints 2
|
a = 3 , b = 5 prints 3
but in the two line version the assignment of a happens in the previous line so it doesnt happen at the same time so
a = 1 , b = 2 prints 1
/
/
a = 2 , b = 4 prints 2
/
/
a = 4 , b = 8
hope that helps.
basically the second one does two assignments where the first one does only one
draw it on paper, it might help understand
0
'b' is assigned to 'a' variable
'a+b' is assigned to 'b' variable
but it is a simultaneous assignment of values
fibonacci?