3. 内置常量¶
有少数的常量存在于内置命名空间中。 它们是:
-
False¶ bool类型的假值。 给False赋值是非法的并会引发SyntaxError。
-
True¶ bool类型的真值。 给True赋值是非法的并会引发SyntaxError。
-
None¶ NoneType类型的唯一值。None经常用于表示缺少值,当因为默认参数未传递给函数时。 给None赋值是非法的并会引发SyntaxError。
-
NotImplemented¶ 二进制特殊方法应返回的特殊值(例如,
__eq__()、__lt__()、__add __()、__rsub__()等)表示操作没有针对其他类型实现;为了相同的目的,可以通过就地二进制特殊方法(例如,__imul __()、__ rightnd__()等)返回。 它的逻辑值为真。
注解
When NotImplemented is returned, the interpreter will then try the
reflected operation on the other type, or some other fallback, depending
on the operator. If all attempted operations return NotImplemented, the
interpreter will raise an appropriate exception.
See 实现算数运算 for more details.
-
Ellipsis¶ The same as
.... Special value used mostly in conjunction with extended slicing syntax for user-defined container data types.
注解
变量名 None,False,True 和 __ debug__ 无法重新赋值(赋值给它们,即使是属性名,将引发 SyntaxError ),所以它们可以被认为是“真正的”常数。
