[英]Why does None lack a docstring?
据我所知,Python中的每个内置对象都有一个文档字符串。 除了我今天刚刚发现的以外,没有。 为什么是这样?
None
有没有其他的功能,而不是存在 。 它是一个实例,而不是类型,而其他内置变量始终是可调用的,或者是某种实例。
字符串,数字,布尔值等都有一个可调用的类型对象,该对象通常还具有特定的转换功能( bool()
, int()
, str()
)。 None
没有; 它的类型不会产生任何结果,因为只有一个实例:
>>> type(None)
<type 'NoneType'>
>>> type(None)()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'NoneType' instances
None
一个不是唯一这样的对象。 Ellipsis
和NotImplemented
是其他这样的对象:
>>> Ellipsis.__doc__ is None
True
>>> NotImplemented.__doc__ is None
True
>>> type(Ellipsis)()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'ellipsis' instances
>>> type(NotImplemented)()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'NotImplementedType' instances
它们都是哨兵 ,是表示特定状态或值的对象,但在该功能之外无用。
因此,它们可能对如何使用而不是如何创建具有意义。 记录此内容的正确位置是Datamodel参考文档 ,而不是docstrings。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.