PythonのNoneTypeをどのように判定するか。
Pythonで、変数の型を判断するにはtype()関数を使用することができます。変数がNoneタイプ、つまりNoneTypeの場合、type()関数はNoneTypeを返します。例えば:
x = None
if type(x) == type(None):
print("x is NoneType")
else:
print("x is not NoneType")
結果は以下の通りです:
x is NoneType