Explanation of list reference

Ian Kelly ian.g.kelly at gmail.com
Sat Feb 15 12:11:46 EST 2014


On Sat, Feb 15, 2014 at 9:29 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
>> On Sat, 15 Feb 2014 14:07:35 +0200, Marko Rauhamaa wrote:
>>> Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
>>>> On Sat, 15 Feb 2014 12:13:54 +0200, Marko Rauhamaa wrote:
>>>>>    5. id(x) == id(y) iff x is y
>>>>
>>>> # Counter-example
>>>> py> x = 230000
>>>> py> idx = id(x)
>>>> py> del x
>>>> py> y = 420000
>>>> py> idy = id(y)
>>>> py> idx == idy
>>>> True
>>>
>>> I don't accept that as a counterexample.
>
>> Why?
>
> Nowhere do I see the violating "x is y".

You formulated your rule as a rule of inference.  The logical
inference from the above is that x is y, which is false even if it
can't be directly tested in Python.

>> All I need to do is show a case where two distinct objects have the
>> same ID.
>
> How do you know objects are "distinct"? Myself, I would use the "is"
> test.

Eliding over details of how one knows that both of the literals above
create objects, if the objects are separately created, then they are
distinct objects.

>>> That's the point. I don't think id() and "is" have any abstract
>>> meaning on top of the formal axioms.
>>
>> Who is talking about "abstract meaning"?
>
> I am. I mean, "implementation-independent".
>
>> Object identity is simple and well-defined in Python. I don't know why
>> you are so resistant to this. Read the documentation.
>
> It is not defined at all:
>
>    Every object has an identity, a type and a value. An object's
>    identity never changes once it has been created; you may think of it
>    as the object's address in memory. The 'is' operator compares the
>    identity of two objects; the id() function returns an integer
>    representing its identity.
>
> Thus "x and y are identical" *means* "x is y" and nothing else.

This notion of identity sounds useless, and if that is the way you
prefer to understand it then you can safely ignore that it exists.  I
think that most users though inherently understand the concept of
objects being distinct or identical and see the value in being able to
test for this.



More information about the Python-list mailing list