A question on modification of a list via a function invocation

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Sep 7 09:21:36 EDT 2017


Rustom Mody wrote:

> I said: In that case please restate the definition of 'is' from the manual which 
> invokes the notion of 'memory' without bringing in memory.

I don't know whether it's in the manual, but at least for
mutable objects, there is a way to define the notion of
"same object" that doesn't require talking about "memory":

Two names refer to the same object if and only if mutations
made through one are visible through the other.

Python has definite rules concerning when mutable objects
will be the same or not, and every correct implementation
must conform to them. In that sense it's a fundamental
concept that doesn't depend on implementation.

There is more leeway when it comes to immutable objects;
implementations are free to cache and re-use them, so
well-written code avoids depending on the result of
"is" for immutable objects.

-- 
Greg



More information about the Python-list mailing list