sross at connectmail.carleton.ca
Mon Oct 27 15:41:27 CET 2003
"Andrew Bennetts" <andrew-pythonlist at puzzling.org> wrote in message
news:mailman.125.1067232717.702.python-list at python.org...
> On Mon, Oct 27, 2003 at 12:08:39AM -0500, Sean Ross wrote:
> > "Michael Loomington" <mloomington at yahoo.ca> wrote in message
> > news:bni80i$11dkvg$1 at ID-198839.news.uni-berlin.de...
> > > I tried doing the following but it doesn't work:
> > >
> > > def __mul__(self, m)
> > > self.r= self.r * m
> > > self.i= self.i * m
> > > return Complex(self.r, self.i)
> > >
> > Hi. Python allows you to define behaviour for both left and right
> > multiplication (instance*2 or 2*instance). See if this helps:
> > 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...
I suppose not. I just went from what the OP already had.
More information about the Python-list