Overloading Less Than And Greater Than

Mon 10 August 2026
class Score:
    def __init__(self, marks):
        self.marks = marks

    def __lt__(self, other):
        return self.marks < other.marks

    def __gt__(self, other):
        return self.marks > other.marks

s1 = Score(85)
s2 = Score(70)

print(s1 > s2)  # True
True


Score: 10

Category: chapter5_operator_overloading