>>> x = 25 * 37
>>> y = 25 * 37
>>> x is y
False
>>> x == y
True
From my understanding, '==' checks for equality and 'is' checks that the variables reference the same address.
>>> x = 25 * 37
>>> y = 25 * 37
>>> x is y
False
>>> x == y
True
From my understanding, '==' checks for equality and 'is' checks that the variables reference the same address.
>>> a=16
>>> a*a is a*a
True
>>> a=17
>>> a*a is a*a
False
WTFSee https://stackoverflow.com/questions/306313/is-operator-behav... for some discussion and further related links.
Otherwise you'll end up thinking that almost everything is simply an alias for constant True or 0 or Error, by popping in 0 to any operator you check.
At the CPython level, you can explain it in terms of the particular range of small integers that are interned and thus are guaranteed within particular CPython versions to share object identity when they have value equality.
But just knowing that is identity and == is equality is mostly enough to use them correctly.