News for hackers. Stuff that matters.
Re:Copying data is wasteful, mutating data is dangerous by ben509 on Friday January 10, 2020 @01:40AM (#22008834)
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.__...

There are no comments on this comment yet.