Built-in Constants,内置常量

只有一点常量在内置的命名空间里。
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值