2 ms·
> a case where x+=y was not equivalent to x=x+y This is true for lists in Python. `a = a + b` creates a new list, but `a += b` works in-place: >>> a = [1,
by pansa2 6y ago
> a case where x+=y was not equivalent to x=x+y
This is true for lists in Python. `a = a + b` creates a new list, but `a += b` works in-place:
>>> a = [1, 2]
>>> b = a
>>> a = a + [3]
>>> print(a, b)
[1, 2, 3] [1, 2]
>>> a = [1, 2]
>>> b = a
>>> a += [3]
>>> print(a, b)
[1, 2, 3] [1, 2, 3]
There are other issues with the `+=`-style operators as well - IMO it was a mistake to have `a += b` be anything other than a shorthand for `a = a + b`.