A newbie question

Dan Bishop danb_83 at yahoo.com
Mon May 21 19:22:06 EDT 2007


On May 21, 6:04 pm, "wang frank" <f... at hotmail.co.jp> wrote:
> Hi,
>
> I am trying to write a python class with a new data type such as:
> class Cc14:
>        def __init__(self, realpart, imagpart):
>                  self.r=realart
>                  self.i=imagpart
>
>        def __add__(self,x):
>                  return self.r+x,r, self.i+x.i
>
> If I have
> x=Cc14(4,5)
> y=Cc14(4,5)
> z=x+y
>
> z will be a tuple instead of Cc14. How can I return a Cc14 class?

return Cc14(self.r+x,r, self.i+x.i)

FYI, Python has a built-in "complex" type.




More information about the Python-list mailing list