class_binop.py 687 B

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