I don't understand why the tortured bytecode for 0==0 is 0, but the reason for warning about 0 is 0 is because of this.
file junk.py
x = 0
file test.py
import junk
x = 0
print(x==junk.x is x)
When I run test.py
Output:
True
But if I change the value from 0 to 257
Output:
False
And if change the value to 256
Output:
True
The reason for this very odd behavior is Python reuses int objects for common int literals (0 to 256). Int literals outside this range are created on a as needed basis. So if x and y are the same int value, x == y is True, but x is y depends on the value of x.
And to make things more confusing, Python reuses literals when loading your module.
x=257
y=257
print(x==y is x)
Output:
True
Even though x and y are outside the "magic" range, Python only created one int object that is assigned to both x and y. Since 257 is an int, and int objects are immutable, there is no reason to create two int objects. When Python is converting the module to bytecodes it sees that 257 is used twice, and decides to save some space and some time and reuse the 257 int object. This optimization is not possible when the same int constant is used in two different modules (thus the reason for junk.py in my example).
So while 0==0 is 0 is an interesting bit of trivia, it really doesn't matter what value it returns. You should never use code that looks like this.