发布时间:2019-07-23 09:41:52编辑:auto阅读(1614)
#-*- coding: utf-8 -*- class C: def __init__(self, i): self.i = i def __cmp__(self, other): return cmp(self.i, other.i) #正向返回值 class D: def __init__(self, i): self.i = i def __cmp__(self, other): return - cmp(self.i, other.i) #这里有 - 则反向返回值 #return cmp(self.i, other.i) print cmp(C(1), C(2))#第一个数小返回-1 print cmp(C(2), C(2))#相等返回0 print cmp(C(3), C(2))#第一个数小返回1 print "反向返回值" print cmp(D(1), D(2)) print cmp(D(2), D(2)) print cmp(D(3), D(2))
结果:
-1
0
1
反向返回值
1
0
-1
上一篇: python小波变换去噪
下一篇: Python学习-hashlib
47485
45787
36785
34318
28956
25590
24437
19607
19103
17628
5459°
6042°
5565°
5633°
6567°
5371°
5371°
5879°
5852°
7164°