Python 判断 NoneType 的两种方法
在 Python 中,可以使用 is 关键字来判断一个对象是否为 NoneType。例如:
x = None
if x is None:
print('x is NoneType')
else:
print('x is not NoneType')
输出:
x is NoneType
另外,也可以使用 type 函数获取对象的类型,并判断是否为 NoneType。例如:
x = None
if type(x) == type(None):
print('x is NoneType')
else:
print('x is not NoneType')
输出:
x is NoneType
原文地址: http://www.cveoy.top/t/topic/f1Yw 著作权归作者所有。请勿转载和采集!