I know that comparison of types is not recommended, but I have some code that does this in an if elif series. However, I am confused as to how None values work.
def foo(object) otype = type(object) #if otype is None: # this doesn't work if object is None: # this works fine print("yep") elif otype is int: elif ... How come I can compare just fine with is int and so forth, but not with is None? types.NoneType seems to be gone in Python 3.2, so I can't use that...
The following
i = 1 print(i) print(type(i)) print(i is None) print(type(i) is int) prints
1 <class 'int'> False True whereas
i = None print(i) print(type(i)) print(i is None) print(type(i) is None) prints
None <class 'NoneType'> True False I guess None is special, but what gives? Does NoneType actually exist, or is Python lying to me?