is
checks to see if two variables are stored at the same memory location. The following states that the two numbers are stored at different locations in memory:
>>> 512 is (2**9)
False
Very likely, what you really wanted to know was if the numbers were equal. To do that, test for equality:
>>> 512 == (2**9)
True
Exceptional case: None
None
does not have any sensible value. Consequently, checking if something is equal to None
is generally not useful. To find out if some variable is None
, use is
:
>>> x = None
>>> x is None
True