1class foo(object): 2 def __init__(self, value): 3 self.x = value 4 5 def __eq__(self, other): 6 print('eq') 7 return self.x == other.x 8 9 def __lt__(self, other): 10 print('lt') 11 return self.x < other.x 12 13 def __gt__(self, other): 14 print('gt') 15 return self.x > other.x 16 17 def __le__(self, other): 18 print('le') 19 return self.x <= other.x 20 21 def __ge__(self, other): 22 print('ge') 23 return self.x >= other.x 24 25for i in range(3): 26 for j in range(3): 27 print(foo(i) == foo(j)) 28 print(foo(i) < foo(j)) 29 print(foo(i) > foo(j)) 30 print(foo(i) <= foo(j)) 31 print(foo(i) >= foo(j)) 32