Built-in Constants 内置常量 ¶

A small number of constants live in the built-in namespace. They are:

False 虚假

The false value of the bool type. Assignments to False are illegal and raise a SyntaxError.
bool 类型的假值。对 False 的赋值是非法的,并引发 SyntaxError

True 真实的

The true value of the bool type. Assignments to True are illegal and raise a SyntaxError.
bool 类型的真实值。对 True 的赋值是非法的,并引发 SyntaxError


An object frequently used to represent the absence of a value, as when default arguments are not passed to a function. Assignments to None are illegal and raise a SyntaxError. None is the sole instance of the NoneType type.
一个经常用来表示值的缺失的对象,比如当默认参数没有传递给函数时。对 None 的赋值是非法的,并会引发一个 SyntaxErrorNoneNoneType 类型的唯一实例。

NotImplemented 未实现的 ¶

A special value which should be returned by the binary special methods (e.g. __eq__(), __lt__(), __add__(), __rsub__(), etc.) to indicate that the operation is not implemented with respect to the other type; may be returned by the in-place binary special methods (e.g. __imul__(), __iand__(), etc.) for the same purpose. It should not be evaluated in a boolean context. NotImplemented is the sole instance of the types.NotImplementedType type.
特殊值应由二进制特殊方法(例如 __eq__()__lt__()__add__()__rsub__() 等)返回,以指示该操作在其他类型上未实现;可以由就地二进制特殊方法(例如 __imul__()__iand__() 等)出于同样的目的返回。它不应该在布尔环境中进行评估。 NotImplementedtypes.NotImplementedType 类型的唯一实例。


When a binary (or in-place) method returns NotImplemented the interpreter will try the reflected operation on the other type (or some other fallback, depending on the operator). If all attempts return NotImplemented, the interpreter will raise an appropriate exception. Incorrectly returning NotImplemented will result in a misleading error message or the NotImplemented value being returned to Python code.

注意:当一个二进制(或原地)方法返回 NotImplemented 时,解释器将尝试在另一种类型上执行反射操作(或者根据运算符的不同选择其他回退方法)。如果所有尝试都返回 NotImplemented ,解释器将引发适当的异常。错误地返回 NotImplemented 将导致一个误导性的错误消息或 NotImplemented 值被返回给 Python 代码。

See Implementing the arithmetic operations for examples.


NotImplementedError and NotImplemented are not interchangeable, even though they have similar names and purposes. See NotImplementedError for details on when to use it.

请注意, NotImplementedErrorNotImplemented 不能互换使用,尽管它们的名称和用途相似。有关何时使用它的详细信息,请参见 NotImplementedError

Changed in version 3.9: Evaluating NotImplemented in a boolean context is deprecated. While it currently evaluates as true, it will emit a DeprecationWarning. It will raise a TypeError in a future version of Python.
从 3.9 版本开始更改:在布尔上下文中评估 NotImplemented 已被弃用。虽然它当前评估为 true,但它将发出 DeprecationWarning 。在未来的 Python 版本中,它将引发 TypeError

Ellipsis 省略号 ¶

The same as the ellipsis literal “...”. Special value used mostly in conjunction with extended slicing syntax for user-defined container data types. Ellipsis is the sole instance of the types.EllipsisType type.
与省略号字面值“ ... ”相同。主要与扩展切片语法一起用于用户定义的容器数据类型。 Ellipsistypes.EllipsisType 类型的唯一实例。


This constant is true if Python was not started with an -O option. See also the assert statement.
如果 Python 没有使用 -O 选项启动,则此常量为真。另请参见 assert 语句。


The names None, False, True and __debug__ cannot be reassigned (assignments to them, even as an attribute name, raise SyntaxError), so they can be considered “true” constants.

注意,名称 NoneFalseTrue__debug__ 不能重新赋值(即使作为属性名称进行赋值也会引发 SyntaxError ),因此它们可以被视为“真正”的常量。

Constants added by the site module
site 模块添加的常量¶

The site module (which is imported automatically during startup, except if the -S command-line option is given) adds several constants to the built-in namespace. They are useful for the interactive interpreter shell and should not be used in programs.
site 模块(在启动时自动导入,除非给出 -S 命令行选项)向内置命名空间添加了几个常量。它们对于交互式解释器 shell 很有用,不应在程序中使用。

quit(code=None) 退出(code=None)¶
exit(code=None) 退出(代码=无)¶

Objects that when printed, print a message like “Use quit() or Ctrl-D (i.e. EOF) to exit”, and when called, raise SystemExit with the specified exit code.
打印时输出如“使用 quit()或 Ctrl-D(即 EOF)退出”,调用时引发指定的退出码。 SystemExit

credits 学分

Objects that when printed or called, print the text of copyright or credits, respectively.

license 许可证

Object that when printed, prints the message “Type license() to see the full license text”, and when called, displays the full license text in a pager-like fashion (one screen at a time).