Click on person_lt.py to get source.
from functools import total_ordering
@total_ordering
class Person(object):
def __init__(self, name, age):
self.name = name
self.age = age
def is_old(self):
return self.age > 40
def __lt__(self,other):
return self.name < other.name
def __eq__(self,other):
return self.name == other.name
erich = Person('Erich', 67)
chay = Person('Chay',22)
print('erich < chay',erich < chay)
print('erich <= chay',erich <= chay)
print('erich == chay',erich == chay)
print('erich > chay',erich > chay)
print('erich >= chay',erich >= chay)
print('erich != chay',erich != chay)