Steve D'Aprano wrote:
py> class K: # defines an object
...     def __init__(self, x):
...             self.x = x
...     def append(self, value):
...             self.x.append(value)
...
py> a = []
py> b = K(a)
py> a is b  # these are not the same object (they're different types)
False
py> b.append(99)  # but modifying b modifies a
py> a
[99]

You didn't mutate the object bound to b there,
you mutated the one bound to b.x, which is
also bound to a.

All you've shown is that just because a method
is named "append" doesn't mean it mutates the
object it's a method of. :-)

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to