[Tutor] Integer ID Caching
wormwood_3 at yahoo.com
Tue Sep 4 15:06:49 CEST 2007
I came across the topic of internal Python IDs recently, and learned that the internal numeric ids of small integers are cached to increase speed. I had read that as of 2.5, this applied to integers between -1 and 100. However, doing some quick tests, this seems not to be accurate:
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 10
>>> b = 10
>>> print id(a), id(b)
>>> c = 250
>>> d = 250
>>> print id(c), id(d)
>>> e = 300
>>> f = 300
>>> print id(e), id(f)
So the upper end of the interning range appears to be between 250 and 300, not 100.
Does anyone know the exact number, when it changed, and if a decision has been made for future changes? I was unable to find anything specific to this in the documentation.
Thanks as always,
More information about the Tutor