""" vector.py | . A = (x1,y1) | ------+------ | | . B = (x2,y2) A + B using vector addition (x1+x2, y1+y2) """ class Vector: def __init__(self, x,y): self.x = x self.y = y def __str__(self): return f"Vector({self.x}, {self.y})" def __add__(self, other): # v1 + v2 turns into v1.add(v2) if they are Vectors # and this Vector.__add__(v1, v2) implements that. return Vector( self.x + other.x, self.y + other.y ) def main(): a = Vector(1, 2) print("A is ", a) b = Vector(10, 20) print("B is ", b) c = a + b print("C is ", c) if __name__ == '__main__': main()