Your difference occurs in the lines:
1)
>>> a, b = 0, 1 >>> a, b = b, a+b >>> a 1 >>> b 1
vs
2)
>>> a, b = 0, 1 >>> a = b >>> b = a+b >>> a 1 >>> b 2
in the first case, a = 1 and b = 0 + 1 until the values ββof the variables change. You basically say "with (a,b) in the given state X, set (a,b) to the values (0,1) ."
A good way to see the difference in such things is to use the disassemble module (see the link to see the meaning of the codes):
>>> from dis import dis >>> a, b = 0, 1 >>> dis('a, b = b, a+b') 1 0 LOAD_NAME 0 (b) 3 LOAD_NAME 1 (a) 6 LOAD_NAME 0 (b) 9 BINARY_ADD 10 ROT_TWO 11 STORE_NAME 1 (a) 14 STORE_NAME 0 (b) 17 LOAD_CONST 0 (None) 20 RETURN_VALUE >>> a, b = 0, 1 >>> dis('a = b; b = a+b') 1 0 LOAD_NAME 0 (b) 3 STORE_NAME 1 (a) 6 LOAD_NAME 1 (a) 9 LOAD_NAME 0 (b) 12 BINARY_ADD 13 STORE_NAME 0 (b) 16 LOAD_CONST 0 (None) 19 RETURN_VALUE
user559633
source share