class Vec2D(tuple): """A 2 dimensional vector class, used as a helper class for implementing turtle graphics. .... """ def __new__(cls, x, y): return tuple.__new__(cls, (x, y)) def __add__(self, other): return Vec2D(self[0]+other[0], self[1]+other[1]) def __mul__(self, other): if isinstance(other, Vec2D): return self[0]*other[0]+self[1]*other[1] return Vec2D(self[0]*other, self[1]*other) def __rmul__(self, other): if isinstance(other, int) or isinstance(other, float): return Vec2D(self[0]*other, self[1]*other) v = Vec2D(0.1, 0.0) a = 10 * v b = 10.0 * v c = v * 10 print "a:", a print "b:", b print "c:", c