Possible Duplicate:
Python “is” operator behaves unexpectedly with integers
Why (0-6) is -6 = False?
>>> (0 - 10) is -10
False
>>> (0 - 5) is -5
True
Can anybody explain me , how I am getting False in one case and True in another case for same manipulation…
Some more weirdness…
>>> (0 - 10) is (0 - 10)
False
Don’t use
isfor equality testing – it’s the identity operator, and two equal objects are not necessarily identical (i. e. residing under the same address in your computer’s memory). Some small integers may be cached and reused but not all of them which is why you’re seeing different results here.Additionally, this behavior is implementation-dependent, so you can’t rely on this always being the case.