Introducing Python to others

Jervis Whitley jervisau at gmail.com
Thu Mar 26 22:32:15 CET 2009


>>>>>> class Vector(list):
>>>
>>> ...   def __add__(self, other):
>>> ...     return map(add, self, other)
>>> ...>>> x = Vector([1,2])

I've used the complex type for a similar problem (2D Cartesian points)
in the past, I saw the suggestion
once on the pygame list.

    >>> x = complex(1,2)
    >>> x + x
    (2 + 4j)

Cheers,

Jervis



More information about the Python-list mailing list