sameness/identity

Oleg Broytmann phd at phd.pp.ru
Mon Oct 1 06:30:36 EDT 2001


On Mon, Oct 01, 2001 at 12:22:52PM +0200, Xavier Defrang wrote:
> > >>> a = 3
> > >>> b = 3
> > >>> a is b
> > 1
> > >>> a = 10000
> > >>> b = 10000
> > >>> a is b
> > 0
> 
> Damn, this is weird. :)
> After reading that, I wrote a small script :
> 
> <snip>
> a = 0
> b = 0
> while a is b:
>     a += 1
>     b += 1
> print id(a), a
> print id(b), b
> </snip>
> 
> Here's the output with Python 2.1:
> 
> <snip>
> 136907204 100
> 136907168 100
> </snip>
> 
> That '100' definetly looks like some hardcoded limit, has anybody a clear
> explanation for this?

   This is really hardcoded limit in the current CPython implementation :)
The interpreter preallocates numbers from 0 to 99.

Oleg.
---- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list