To clarify how Python handles two equal objects

Chris Angelico rosuav at gmail.com
Sat Jan 14 18:51:30 EST 2023


On Sun, 15 Jan 2023 at 10:32, Jen Kris via Python-list
<python-list at python.org> wrote:
> The situation I described in my original post is limited to a case such as x = y ... the assignment can be done simply by "x" taking the pointer to "y" rather than moving all the data from "y" into the memory buffer for "x"
>

It's not simply whether it *can* be done. It, in fact, *MUST* be done
that way. The ONLY meaning of "x = y" is that you now have a name "x"
which refers to whatever object is currently found under the name "y".
This is not an optimization, it is a fundamental of Python's object
model. This is true regardless of what kind of object this is; every
object must behave this way.

ChrisA


More information about the Python-list mailing list