[BangPypers] python id function

Anand Balachandran Pillai abpillai at gmail.com
Thu Jan 7 10:15:44 CET 2010


On Thu, Jan 7, 2010 at 2:16 PM, Anand Balachandran Pillai <
abpillai at gmail.com> wrote:

>
>
>
>
> It is a good exercise to find out the limit till Python caches
> integers. My guess is that it is somewhere close to 100, i.e
> 100+.
>

I wrote a small program to find this out. And
on my Python runtime (2.6.2), the answer is 257.

def intCacheLimit():
    i,l,m=1,range(500),range(500)

    while i<500:
        x=l[i]
        y=m[i]
        if x is not y:
            print 'Limit',x
            break

        i+=1

[anand at localhost python]$ python
Python 2.6.2 (r262:71600, Aug 21 2009, 12:23:57)
[GCC 4.4.1 20090818 (Red Hat 4.4.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from intlimit import *
Limit 257

So Python caches integers till 256 - a nice square integer.
Cool right ?

Others can try it out in other Python versions - my guess
would be it is the same everywhere.


>
>
>


-- 
--Anand


More information about the BangPypers mailing list