class Point(object):

    def __repr__(self):
        return '(' + str(self.x) + ',' + str(self.y) + ')'

def __init__(self, x, y):
    self.x = x
self.y = y

def __add__(self, point):
    return Point(self.x + point.x, self.y + point.y)

def __sub__(self, point):
    return Point(self.x - point.x, self.y - point.y)

def __mul__(self, num):
    return Point(num * self.x, num * self.y)

def __rmul__(self, num):
    return self.__mul__(num)

def length(self):
    return self.x ** 2 + self.y ** 2
x = Point(1, 2)
y = Point(1, 3)
print(x + y)
print(y + x)
print(x - y)
print(y - x)
print(y * 3)
print(3 * y)
Overiding __mul__ in two dimensional vector class to preserve commutivity