Overloading The Addition Operator
Mon 10 August 2026
class Vector:
def __init__(self, x):
self.x = x
def __add__(self, other):
return Vector(self.x + other.x)
v1 = Vector(5)
v2 = Vector(7)
v3 = v1 + v2
print(v3.x) # Output: 12
12
Score: 10
Category: chapter5_operator_overloading