Explanation of list reference

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Feb 15 06:17:56 EST 2014


On Sat, 15 Feb 2014 12:13:54 +0200, Marko Rauhamaa wrote:

> Marko Rauhamaa <marko at pacujo.net>:
> 
>>   1. if x is y then y ix x
>>   2. if x is y and y is z then x is z
>>   3. after x = y, x is y
>>   4. if x is y, then x == y
> 
> A new attempt:
> 
>    0. x is x
>    1. if x is y then y ix x
>    2. if x is y and y is z then x is z
>    3. after x = y, x is y
>    4. if x is y and x == x, then x == y
>    5. id(x) == id(y) iff x is y

Python implementations are free to re-use IDs after the object is 
destroyed. CPython does; Jython and IronPython do not. So #5 needs to 
point out that the condition id(x) == id(y) only applies if x and y still 
exist.

# Counter-example
py> x = 230000
py> idx = id(x)
py> del x
py> y = 420000
py> idy = id(y)
py> idx == idy
True


(This is *implementation dependent* so your mileage my vary.)


> Does that cover it?

No. Your definition describes some properties of identity-equivalence, 
but doesn't explain what identity actually means.


-- 
Steven



More information about the Python-list mailing list