Newbie: Classes

KefX keflimarcusx at aol.comNOSPAM
Mon Oct 27 01:52:16 EST 2003


>> def __mul__(self, m):
>>     self.r *= m
>>     self.i *= m
>>     return Complex(self.r, self.i)
>
>Uh, I don't think you want to mutate this instance...

Yeah, that's right. Do it like this instead:
def __mul__(self, m):
  r *= m
  i *= m
  return Complex(r, m)

Why are you doing a complex class, anyway? Python already supports complex
numbers.

- Kef




More information about the Python-list mailing list