id() and is operator

Marko Rauhamaa marko at pacujo.net
Sun Feb 22 16:25:12 EST 2015


LJ <luisjosenovoa at gmail.com>:

>>>> id(b[0])
> 45855552
[...]
>>>> id(b[2])
> 45855552
>
> Please correct me if I am wrong, but according to this b[2] and b[0]
> are the same object. Now,
>
>>>> b[0] is b[2]
> False

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).


Marko



More information about the Python-list mailing list