Comparisons: __lt__, __gt__
class C: data = 'test' def __gt__(self, other): # 3.X and 2.X version return self.data > other def __lt__(self, other): return self.data < other X = C() # w w w. j av a 2 s .com print(X > 'ham') # True (runs __gt__) print(X < 'ham') # False (runs __lt__)