4. 内置常量

有少数的常量存在于内置命名空间中。 它们是:

False

The false value of the bool type.

2.3 新版功能.

True

The true value of the bool type.

2.3 新版功能.

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 a SyntaxError.

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.

__debug__

如果 Python 没有以 -O 选项启动,则此常量为真值。 另请参见 assert 语句。

注解

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

credits

打印或调用的对象分别打印版权或作者的文本。

license

当打印此对象时,会打印出一条消息“Type license() to see the full license text”,当调用此对象时,将以分页形式显示完整的许可证文本(每次显示一屏)。