Yes. Depending on how the class of x
is coded, the short form has the option to modify x in-place, instead of creating a new object representing the sum and rebinding it back to the same name. This has an implication if you have multiple variables all referring to the same object - eg, with lists:
>>> a = b = []
>>> a += [5]
>>> a
[5]
>>> b
[5]
>>> a = a + [5]
>>> a
[5, 5]
>>> b
[5]
This happens because behind the scenes, the operators call different magic methods: +
calls __add__
or __radd__
(which are expected not to modify either of their arguments) and +=
tries __iadd__
(which is allowed to modify self
if it feels like it) before falling back to the +
logic if __iadd__
isn't there.