python: bug or feature?
Olaf Delgado
delgado at olaf.de
Wed Aug 9 19:26:53 EDT 2000
In article <8msimd$bia$1 at nnrp1.deja.com>,
Keith Murphy <kpmurphy at my-deja.com> writes:
> the first one works, but the second one always returns a 0.
>
> ( (e%4 == 0) & (self.current == e-1) )
>
> ( e%4 == 0 & self.current == e-1 )
So, what did you want it to return?
The '&' stands for a bitwise 'and' operation, which binds stronger
than the test for equality. So the second expression is equivalent to
( e%4 == (0 & self.current) == e-1 )
which, as '0 & anything' is always 0, is equivalent to
( e%4 == 0 == e-1 )
which, in turn, is equivalent to
( e%4 == 0 and 0 == e-1 )
which can only be true if 1 is divisible by 4 (which it isn't, at
least not in ordinary arithmetic).
What you presumably wanted is
( e%4 == 0 and self.current == e-1 )
--
////
Olaf Delgado Friedrichs, Bielefeld, Germany
`=' --- http://www.mathematik.uni-bielefeld.de/~delgado ---
More information about the Python-list
mailing list