I am noticing something peculiar about identity comparison for integers, below and above 256, in python. Take a look at below code.
a = 256 # or any number below
b = 256
print(a is b) # True
a = 257 # or any number above
b = 257
print(a is b) # False
This my guess is that since a number > 256 doesn't fit in an 8 bit memory location, python moves it else where and stores a pointer instead. (I'm not a CS graduate, probably my understanding is completely wrong).
However, if I use multiple assignment. Things are different.
a, b = 257, 257 # or any number above
print(a is b) # True
Is this by design? May be for optimizing memory? Why does python behave like this?
ps: I am using Python 3.6.1