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?
intis a class. if you type justintyou get<class 'int'>iscompares references. You wantisinstance(x,int)isoperator does something very specific, which appears to differ from what you expect.isis not a Boolean operator, it's an identity operator