Permanent objects?

Tom Zych tztemp13 at pobox.com
Tue Dec 24 13:14:55 EST 2002


Here's an odd thing Python 2.2 does:

>>> x = 0
>>> y = 0
>>> x is y
1
>>> x = 99
>>> y = 99
>>> x is y
1
>>> x = 100
>>> y = 100
>>> x is y
0
>>> x = -1
>>> y = -1
>>> x is y
1
>>> x = -2
>>> y = -2
>>> x is y
0

I'm guessing that Python keeps the integers from -1 to 99 as
permanent objects so it doesn't have to create a brand new object
for every piddling little [0] and such. Anyone know?

--
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address is rot13(gbzmlpu at cbobk.pbz).



More information about the Python-list mailing list