In the first example, you've used this code:
a,b=b,a+b
While in the second, you've done this instead:
a = b
b = a+b
These are not the same thing.
For the sake of argument, let's say that a = 3
and b = 6
. Let's run the working code first:
>>> a, b = 10, a + 1
>>> a
10
>>> b
4
The value of a + 1
is 4 rather than 11, because b
's assignment is using the old value of a
, so 3 + 1 == 4
.
Now let's put a
and b
back to their starting values. Let's try the other method of assigning:
>>> a = 10
>>> b = a + 1
>>> a
10
>>> b
11
Now b
is 11! That's because a
was assigned before the assignment of b
, so the addition uses a
's new value.
The reason your second version isn't working is because the assignments don't happen simultaneously, so b
is actually 2 * b
because a
has already been set to b
by the time a+b
is executed.