id() and is operator

Marko Rauhamaa marko at pacujo.net
Mon Feb 23 01:31:04 EST 2015


Terry Reedy <tjreedy at udel.edu>:

> On 2/22/2015 4:25 PM, Marko Rauhamaa wrote:
>> This is a true statement:
>>
>>     If X is Y, then id(X) == id(Y).
>>
>> However, this is generally not a true statement:
>>
>>     If X is Y, then id(X) is id(Y).
>
> If X and Y exist at the *same time*, then (X is Y) == (id(X) is id(Y)).

Sorry, you're wrong:

   Python 3.3.2 (default, Dec  4 2014, 12:49:00) 
   [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux
   Type "help", "copyright", "credits" or "license" for more information.
   >>> x = "alksjdlfkajsf"
   >>> id(x) is id(x)
   False
   >>> (x is x) == (id(x) is id(x))
   False


Marko



More information about the Python-list mailing list