class MyClass:
def __init__(self, x, y):
self.x = x
self.y = y
# tells Python what to do when objects of MyClass are compared using less than operator (<)
def __lt__(self, other):
return self.x < other.x
obj1 = MyClass(5, 10)
obj2 = MyClass(7, 12)
# using less than (<) operator since this is now defined for objects of MyClass
if obj1 < obj2:
print("x from obj1 is less than x from obj2!")