(no) fast boolean evaluation ? missing NOT
Terry Reedy
tjreedy at udel.edu
Fri Aug 3 15:11:00 EDT 2007
"Stef Mientki" <S.Mientki-nospam at mailbox.kun.nl> wrote in message
news:eb4fb$46b2f7a6$d443bb3a$21643 at news.speedlinq.nl...
| John Machin wrote:
| So now I'm left with just one question:
| for bitwise operations I should use &, |, ^
| for boolean operations I should use and, or, xor
| but after doing some test I find strange effects:
| >>> A = 4
| >>> B = 5
| >>> A and B
| 5
>>> B and A
4
| >>> A & B
| 4
| >>> A or B
| 4
>>> B or A
5
| >>> A | B
| 5
|
| So if I use the bitwise operation on integers,
| "and" changes into (bitwise) "or" and vise versa.
No, you hypnotised yourself by generalizing from insufficient data.
Repeat experiment with, for instance, 3 and 4 instead of 4 and 5. Then 3&4
= 0, 3|4 = 7.
tjr
More information about the Python-list
mailing list