I have a python class
class Vector2D(object):
def __init__(self, x, y):
self.x = float(x)
self.y = float(y)
def mag(self):
return sqrt(self.x**2 + self.y**2)
...
I want to be able to multiply vectors together like vector1 * vector2, so I added
def __mul__(self, v):
return Vector2D(self.x * v.x, self.y * v.y)
But I also want to use new_vector = some_vector * 2 and return a new vector like so
def __mul__(self, factor):
return Vector2D(self.x * factor, self.y * factor)
How do I do both?
Check to see if
vis aVector2D, and if not pass it tofloat()and multiply appropriately.