Python a, b = b, a +b

In a, b = b, a + b, the expressions on the right hand side are evaluated before being assigned to the left hand side. So it is equivalent to:

c = a + b
a = b
b = c

In the second example, the value of a has already been changed by the time b = a + b is run. Hence, the result is different.

Leave a Comment