In python, what is the difference between
x = y = 0
and
x = 0
y = 0
In python, what is the difference between
x = y = 0
and
x = 0
y = 0
IIRC, there's no difference for immutable types (like int in the example). But beware of potential issues when doing chained assignment for mutables:
>>> foo = bar = []
>>> print(id(foo) == id(bar))
Out: True
>>> foo.append(1)
>>> bar
Out: [1]
So here you inadvertently modify both lists since they both refer to the same set of memory addresses.
EDIT: Actually, there is a difference in your example. The one-liner chained assignment is more compact but might become less legible so I personally almost never use those.