Copy constructors

Peter Hansen peter at engcorp.com
Mon Aug 13 22:54:46 EDT 2001


Jeff Shannon wrote:
> 
> Erik Max Francis wrote:
> 
> > Ng Pheng Siong wrote:
> >
> > >     self.state = 1 - self.state
> > >
> > > ;-)
> >
> > Why not just
> >
> >         self.state = not self.state
> >
> 
> Because these constructs are limited to representing only two states (0
> and 1), whereas the original construct was easily expandable to an
> arbitrary number of states, even though only two were shown for example
> purposes.

Good point, although I think Erik was suggesting a
better alternative to the x = 1 - x idiom.  Since it
is conceivable that x begins as a value other than
0 or 1, the x = not x idiom immediately brings it 
into the 0 or 1 range, whereas the other way just
has it alternate between two values, which *might*
be zero or one...

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list