-3

Why does this print False in Python 3?

>>> 1 == int
False
 
enzo
  • 9,861
  • 3
  • 15
  • 38
  • Because you're comparing two objects that one of that has the value of 1 and other one doesn't have a value at all. `int` is actually a type object. It denotes a type in python and `1` is an `int` type object. – Mazdak Sep 27 '17 at 11:03
  • Of course `int` has a value; it's just not an *integer* value, but a type value. – chepner Sep 27 '17 at 11:42

2 Answers2

4

Because that isn't at all doing what you think it is. You are comparing the integer value 1 with the type int; naturally they are not equal.

If you want to check whether an object is of a certain type, use isinstance:

isinstance(1, int)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
0

I guess, what you want to use is this:

>>> type(1) is int
True

or

>>> type(1) == int
True
Alperen
  • 3,772
  • 3
  • 27
  • 49