0

I've just run into an issue with Python 3.7 in Spyder console that confused me.

Why does s is int return False, while type(s) returns int?

s = 2

s is int
Out[310]: False

type(s)
Out[311]: int
pawel123
  • 57
  • 1
  • 5
  • 2
    Because `2` is not the `int` class, but an _instance_ of this class. In the same vein, `"hello" is str` will be `False`. Also see this: https://stackoverflow.com/questions/13650293/understanding-pythons-is-operator – ForceBru Feb 16 '20 at 13:42
  • Because the *type* of `s` `is int`, not `s` itself (the value). – deceze Feb 16 '20 at 13:42
  • 4
    I think you are looking for `>>> isinstance(2, int)` – Abdul Niyas P M Feb 16 '20 at 13:42
  • Does this answer your question? [Understanding Python's "is" operator](https://stackoverflow.com/questions/13650293/understanding-pythons-is-operator) – EugeneProut Feb 16 '20 at 13:47

0 Answers0