python: bug or feature?

Huaiyu Zhu hzhu at localhost.localdomain
Wed Aug 9 18:51:23 EDT 2000


This just shows that the current arrangements of logical operators and
bitwise operators is a misfeature.  Bitwise operations do not deserve
cryptic symbols, especially ones with their own precedence levels. :-)

Huaiyu

On 10 Aug 2000 00:32:20 +0200, Bernhard Herzog <herzog at online.de> wrote:
>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) )
>
>You probably meant to use 'and' instead of '&' (& is bitwise and):
>
>   ( (e%4 == 0) and (self.current == e-1) )
>
>which is indeed the same as 
>
>   ( e%4 == 0 and self.current == e-1 )
>
>> ( e%4 == 0 & self.current == e-1 )
>
>This one is equivalent to 
>
>  ( e%4 == (0 & self.current) == e-1 )
>
>which is indeed always 0, assuming e is an integer.
>
>If you come from C or C++, note, that &, | and ^ have higher precedence
>than the comparison operators and that the comparison operators can be
>chained, i.e. a < b < c does what you'd expect from maths and not what
>you'd expect from C.
>



More information about the Python-list mailing list