So how can I question a variable that is a NoneType?
Use is operator, like this
if variable is None:
Why this works?
Since None is the sole singleton object of NoneType in Python, we can use is operator to check if a variable has None in it or not.
Quoting from is docs,
The operators
isandis nottest for object identity:x is yis true if and only ifxandyare the same object.x is not yyields the inverse truth value.
Since there can be only one instance of None, is would be the preferred way to check None.
Hear it from the horse’s mouth
Quoting Python’s Coding Style Guidelines – PEP-008 (jointly defined by Guido himself),
Comparisons to singletons like
Noneshould always be done withisoris not, never the equality operators.