3 ms·
It's because of Python's distinction (enforced mainly by convention) between references and value types. If you are using a value type, `__iadd__`[1] can retur
by ben509 7y ago
It's because of Python's distinction (enforced mainly by convention) between references and value types.
If you are using a value type, `__iadd__`[1] can return a new value. So:
x = 5
y = x
x += 3
y is not x and y == 5
But if you're using a reference type, it is allowed to mutate the reference and return the original reference.
x = [1, 2]
y = x
x += [3, 4]
y is x and y == [1, 2, 3, 4]
[1]: https://docs.python.org/3/reference/datamodel.html#object.__iadd__ https://docs.python.org/3/reference/datamodel.html#object.__...