I want to show someone how using is instead of == to compare integers can fail. I thought this would work, but it didn\'t:
>>
What you observe is expected:
>>> x=256
>>> y=256
>>> x is y
True
>>> x=257
>>> y=257
>>> x is y
False
>>> x=-5
>>> y=-5
>>> x is y
True
>>> x=-6
>>> y=-6
>>> x is y
False
Quoting from Plain Integer Objects:
The current implementation keeps an array of integer objects for all integers between
-5and256, when you create an int in that range you actually just get back a reference to the existing object. So it should be possible to change the value of1. I suspect the behaviour of Python in this case is undefined. :-)