[Tutor] subscript problem
Magnus Lyckå
magnus@thinkware.se
Wed Jun 4 10:11:11 2003
At 16:50 2003-06-04 +0530, Jimmy verma wrote:
>I am having some curves, whose points i am trying to store with Vec and AB.
Wouldn't it be simpler to just do:
curve = [(x0, y0), (x1, y1), ... (xn, yn)]
It's common to simply use a tuple in Python where structs are
used in other languages. Or use complex numbers if you don't like
to access with [0] for x coordinate and [1] for y coordinate.
>>> coord0 = complex(1.123, 4.5)
>>> coord0.real
1.123
>>> coord0.imag
4.5
Then you have the arithetic you need if you for instance want to
see the difference between to coords.
>>> coord1 = complex(1.623, 5.5)
>>> diff = coord1-coord0
>>> diff.real
0.5
>>> diff.imag
1.0
--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language