在Python3中,我想判断value
是字符串还是None
.
一种方法是
assert type(value) in { str, NoneType }
但是NoneType
在Python中位于哪里?
如果没有任何进口,使用NoneType
产生NameError: name 'NoneType' is not defined
.
在Python3中,我想判断value
是字符串还是None
.
一种方法是
assert type(value) in { str, NoneType }
但是NoneType
在Python中位于哪里?
如果没有任何进口,使用NoneType
产生NameError: name 'NoneType' is not defined
.
types.NoneType
将在Python 3.10中重新引入.
Improved Modules
重新引入了
types.EllipsisType
、types.NoneType
和types.NotImplementedType
类,提供了一组可由类型判断器轻松解释的新类型.(由巴斯·范比克于bpo-41810年撰稿.)
关于这一变化的讨论是出于对types.EllipsisType
的需求,结果types.NoneType
也变成了added for consistency.