Skip to content Skip to sidebar Skip to footer

Determining A Variable's Type Is NoneType In Python

I would like to check if a variable is of the NoneType type. For other types we can do stuff like: type([])==list But for NoneType this simple way is not possible. That is, we

Solution 1:

NoneType just happens to not automatically be in the global scope. This isn't really a problem.

>>> NoneType = type(None)
>>> x = None
>>> type(x) == NoneType
True
>>> isinstance(x, NoneType)
True

In any case it would be unusual to do a type check. Rather you should test x is None.


Solution 2:


Post a Comment for "Determining A Variable's Type Is NoneType In Python"