在 Python 中,可以使用 type() 函数来判断一个变量的数据类型。因此,要判断一个变量是否属于 <class 'NoneType'> 类型,可以使用以下代码:

x = None
if type(x) == type(None):
    print('x is NoneType')
else:
    print('x is not NoneType')

输出结果为:

x is NoneType

其中,None 是 Python 中表示空值的特殊对象,它是一个单独的类型,即 <class 'NoneType'>。因此,如果一个变量的值为 None,则它的类型就是 NoneType,可以使用上述代码来判断。

Python 判断变量是否为 None:使用 type() 函数