When I do this:
>>> 1 is int
False
It returns False
, even when I would expect it to return True
. The same behavior occurs when attempting to type-check a variable.
>>> a = 1
>>> a is int
False
I understand that this has something to do with using is
instead of isinstance
or type
.
>>> type(1)
<class 'int'>
>>> isinstance(1, int)
True
>>> type(1) is int
True
Could someone explain exactly why using is
does not work in this case? It makes sense to me semantically that it would return True
instead of False
.