is None or == None ?

Marco Mariani marco at sferacarta.com
Fri Nov 6 10:51:18 EST 2009


Alf P. Steinbach wrote:

> If you imagine that instead, for an integer variable x it stores the 
> integer value in the variable in some other place than ordinarily used 
> for pointer, and let the pointer point to that place in the same 
> variable, then without checking type the 'is' operator should report 
> false for 'x = 3; y = 3; x is y', but it doesn't with my Python 

Yes, CPython caches a handful of small, "commonly used" integers, and 
creates objects for them upon startup. Using "x is y" with integers 
makes no sense and has no guaranteed behaviour AFAIK

> In short, you're saying that there is an extreme inefficiency with every 
> integer dynamically allocated /plus/, upon production of an integer by 
> e.g. + or *, inefficiently finding the previously allocated integer of 
> that value and pointing there,

no, it doesn't "point there":

>>>> a=1E6
>>>> a is 1E6
> False
>>>> a=100
>>>> a is 100
> True



More information about the Python-list mailing list