Built-in Constants内建常量¶
A small number of constants live in the built-in namespace. 内置名称空间中存在少量常量。They are:它们是:
-
False
¶ The false value of thebool
type.bool
类型的false
值。Assignments to对False
are illegal and raise aSyntaxError
.False
的赋值是非法的,会引起SyntaxError
。
-
True
¶ The true value of thebool
type.bool
类型的真实值。Assignments to赋值为True
are illegal and raise aSyntaxError
.True
是非法的,会引起SyntaxError
。
-
None
¶ 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 aSyntaxError
.None
是非法的,并且会引起语法错误。None
is the sole instance of the是NoneType
type.NoneType
的唯一实例。
-
NotImplemented
¶ A special value which should be returned by the binary special methods (e.g.应通过二进制特殊方法返回的特殊值(例如__eq__()
,__lt__()
,__add__()
,__rsub__()
, etc.)__eq__()
、__lt__()
、__add_()
和__rsub__()
等)。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.__imul__()
和__iand__()
等)返回实机相同的目的。It should not be evaluated in a boolean context.不应在布尔上下文中对其求值。NotImplemented
is the sole instance of the是types.NotImplementedType
type.types.NotImplementedType
类型的唯一实例。Note
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).NotImplemented
时,解释器将在其他类型上尝试反射操作(或其他某种回退,取决于运算符)。If all attempts return如果所有尝试都返回NotImplemented
, the interpreter will raise an appropriate exception.NotImplemented
,解释器将引发相应的异常。Incorrectly returning错误地返回NotImplemented
will result in a misleading error message or theNotImplemented
value being returned to Python code.NotImplemented
将导致错误消息或NotImplemented
值返回给Python代码。See Implementing the arithmetic operations for examples.有关示例,请参阅实现算术运算。Note
NotImplementedError
andNotImplemented
are not interchangeable, even though they have similar names and purposes.NotImplementedError
和NotImplemented
不可互换,即使它们有相似的名称和用途。See有关何时使用它的详细信息,请参阅NotImplementedError
for details on when to use it.NotImplementedError
。Changed in version 3.9:在版本3.9中更改:Evaluating不推荐在布尔上下文中计算NotImplemented
in a boolean context is deprecated.NotImplemented。
While it currently evaluates as true, it will emit a虽然它当前的计算结果为DeprecationWarning
.true
,但它将发出一个DeprecationWarning
。It will raise a它将在Python的未来版本中引发TypeError
in a future version of 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 thetypes.EllipsisType
type.Ellipsis
是types.EllipsisType
类型的唯一实例。
-
__debug__
¶ This constant is true if Python was not started with an如果Python不是以-O
option.-O
选项启动的,则该常量为true
。See also the另请参见assert
statement.assert
语句。
Note
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.None
、False
、True
和__debug__
(分配给它们,即使作为属性名称,也会引发语法错误),因此可以将它们视为“True
”常量。
Constants added by the site
modulesite
模块添加的常量¶
site
moduleThe 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. site
模块(在启动期间自动导入,除非给定了-S
命令行选项)向内置名称空间添加了几个常量。They are useful for the interactive interpreter shell and should not be used in programs.它们对于交互式解释器外壳非常有用,不应在程序中使用。
-
quit
(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
。
-
copyright
¶ -
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).对象,打印时打印消息“Typelicense()
以查看完整的许可证文本”,调用时以类似寻呼机的方式(一次一个屏幕)显示完整的许可证文本。