摘要: operator模块提供一下特殊方法,可以将类的实例使用下面的操作符来操作 运算符 特殊方法 含义 <,<=,==,>,>=,!= __lt__,__le__,__eq__,__gt__,__ge__,__ne__ 比较运算符 +,-,*,/,%,//,**,divmod __add__,__sub 阅读全文
posted @ 2020-10-05 23:22 ascertain 阅读(97) 评论(0) 推荐(0) 编辑
摘要: __bool__ 内建函数bool(),或者对象放在逻辑表达式的位置,调用这个函数返回布尔值,没有定义__bool__(),就找__len__()返回长度,非0为真,如果__len__()也没有定义,所有实例都返回真 class B:pass print(bool(B())) class C: de 阅读全文
posted @ 2020-10-05 17:41 ascertain 阅读(98) 评论(0) 推荐(0) 编辑
摘要: __hash__: 内建函数hash()调用的返回值,返回一个整数,如果定义这个方法该类的实例就可hash class M: b=899 def __init__(self): self.hy=44 pass def __hash__(self): return 89 # __hash__=None 阅读全文
posted @ 2020-10-05 16:00 ascertain 阅读(238) 评论(0) 推荐(0) 编辑
摘要: __name__ 类,函数,方法的名字 __module__ 类,函数,方法所在的模块名 __class__ 类,对象,函数所属的类所有的函数和方法均属于<class 'function'> def bnm():pass class P: def uo(self):pass print(bnm.__ 阅读全文
posted @ 2020-10-05 14:18 ascertain 阅读(196) 评论(0) 推荐(0) 编辑
摘要: p='''bottle\r\nbag\r\nbig\napple''' import re regex=re.compile(r'\bb(?P<middle>\w)(?P<tail>g)') mat=regex.finditer(p) print(mat) for m in mat: print(m 阅读全文
posted @ 2020-10-05 13:51 ascertain 阅读(1173) 评论(0) 推荐(0) 编辑
摘要: class SimplexNode: def __init__(self,value,post=None,prev=None): self.value=value self.post=post self.prev=prev def __repr__(self): # return 'Node: {} 阅读全文
posted @ 2020-10-05 02:53 ascertain 阅读(162) 评论(0) 推荐(0) 编辑