id( ) function question

Tim Chase python.list at
Wed Oct 14 13:21:55 CEST 2009

> But if I chose as a value another number (a big one, let say 1e10) I
> get what I will expect also in the case of the chose of the integer 10
> showed above:
>>>> a=1e10
>>>> d=1e10
>>>> d is a
> False
>>>> id(a)
> 11388984
>>>> id(d)
> 11388920

CPython has the option to cache frequently used items, and does 
so for a small range of ints.  It's not guaranteed behavior (or a 
guaranteed range) so you shouldn't rely on it, but it's an 
efficiency thing.  In my current version, it looks like it's ints 
from -5 to 256. YMMV

In general, if you're using "is" (and not comparing with None) or 
id(), you're doing it wrong unless you already know the 
peculiarities of Python's identity implementations.


More information about the Python-list mailing list