4. 内置常量¶
有少数的常量存在于内置命名空间中。 它们是:
-
None
¶ The sole value of
types.NoneType
.None
is frequently used to represent the absence of a value, as when default arguments are not passed to a function.在 2.4 版更改: Assignments to
None
are illegal and raise aSyntaxError
.
-
NotImplemented
¶ Special value which can be returned by the “rich comparison” special methods (
__eq__()
,__lt__()
, and friends), to indicate that the comparison is not implemented with respect to the other type.
-
Ellipsis
¶ Special value used in conjunction with extended slicing syntax.
注解
The names None
and __debug__
cannot be reassigned
(assignments to them, even as an attribute name, raise SyntaxError
),
so they can be considered “true” constants.
在 2.7 版更改: Assignments to __debug__
as an attribute became illegal.
4.1. 由 site
模块添加的常量¶
site
模块(在启动期间自动导入,除非给出 -S
命令行选项)将几个常量添加到内置命名空间。 它们对交互式解释器 shell 很有用,并且不应在程序中使用。
-
quit
([code=None])¶ -
exit
([code=None])¶ 当打印此对象时,会打印出一条消息,例如“Use quit() or Ctrl-D (i.e. EOF) to exit”,当调用此对象时,将使用指定的退出代码来引发
SystemExit
。
-
license
¶ 当打印此对象时,会打印出一条消息“Type license() to see the full license text”,当调用此对象时,将以分页形式显示完整的许可证文本(每次显示一屏)。