Search code examples
pythonbooleanboolean-logicboolean-expression

Python Boolean comparison


I'm testing Python's Boolean expressions. When I run the following code:

x = 3
print type(x)
print (x is int)
print (x is not int)

I get the following results:

<type 'int'>
False
True

Why is (x is int) returning false and (x is not int) returning true when clearly x is an integer type?


Solution

  • If you want to use is you should do:

    >>> print (type(x) is int)
    True