只有一点常量在内置的命名空间里。
False
,
,
,
True
,
,
,
None NoneType的唯一值,代表无。
,
,
,
NotImlemented 请看下面这个例子
class Person:
def __init__(self, age):
self.age = age
def __eq__(self, other):
if not isinstance(other, Person):
print('第一次')
return NotImplemented#解释器收到这个值就会寻求比较操作符==另一边的__eq__。
return self.age == other.age
class Person1:
def __init__(self, age):
self.age = age
def __eq__(self, other):#最后person == person1中 == 执行的的方法。
print('fallback on Person1')
return self.age == other.age
person = Person(10)
person1 = Person1(10)
print(person == person1) # True
运行结果如下:
第一次
fallback on Person1
True
‘person==person1’首先会调用person的__eq__,结果返回常量NotImplement,解释器转而寻求person1(退而求谁和operation有关系)的__eq__,这就是这个常量的功能。
,
,
,
Ellipsis
Ellipsis==...#True
用处:
用…代替pass,其实没必要,只要是个字面值都行。
def lqq():
…
循环数据结构, 一个复合对象包含指向自身的引用
L = [1,2,3]
L.append(L)
print(L)#[1,2,3,[…]]
.用来模拟一些情况,使结果看起来更友好,如等差数列,numpy。
,
,
,
_ debug_
This constant is true if Python was not started with an -O option.
,
,
,
除了以上,site 模块加入了以下常量。site会在开始运行时加载。以下常量不推荐在程序中使用,设计在交互模式使用的
quit(code=None)
exit(code=None)
copyright
credits
license