Overloading The Subtraction Operator
Mon 10 August 2026
class Balance:
def __init__(self, amount):
self.amount = amount
def __sub__(self, other):
return Balance(self.amount - other.amount)
b1 = Balance(100)
b2 = Balance(40)
result = b1 - b2
print(result.amount) # Output: 60
60
Score: 10
Category: chapter5_operator_overloading