Python's weird behavior is

Python version: Python 3.5.1 (v3.5.1: 37a07cee5969, December 6, 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32.

>>> 256 is (2**8)
True
>>> 512 is (2**9)
False

UPD

>>> print(id(256), id(2**8))
1933723392 1933723392
>>> print(id(512), id(2**9))
60976880 60976704
+4
source share
1 answer

ischecks if two variables are stored in the same memory location. The following states indicate that these two numbers are stored in different places in memory:

>>> 512 is (2**9)
False

Most likely, you really wanted to know if the numbers were equal. To do this, check the equality:

>>> 512 == (2**9)
True

Exceptional case: None

Nonehas no reasonable meaning. Therefore, checking that something is equal is Noneusually not useful. To find out if there is any variable None, use is:

>>> x = None
>>> x is None
True
+2

Source: https://habr.com/ru/post/1651862/


All Articles