and becomes or and or becomes and
Colin J. Williams
cjw at ncf.ca
Mon May 23 08:20:16 EDT 2011
On 22-May-11 15:23 PM, Stef Mientki wrote:
> hello,
>
> must of us will not use single bits these days,
> but at first sight, this looks funny :
>
>>>> a=2
>>>> b=6
>>>> a and b
> 6
>>>> a& b
> 2
>>>> a or b
> 2
>>>> a | b
> 6
>
> cheers,
> Stef
5.2. Boolean Operations — and, or, not
These are the Boolean operations, ordered by ascending priority:
Operation Result Notes
x or y if x is false, then y, else x (1)
x and y if x is false, then x, else y (2)
not x if x is false, then True, else False (3)
The second line is puzzling at first look, but consistent.
It is analogous to the Conditional Expression.
See:
http://docs.python.org/reference/expressions.html#conditional-expressions
Colin W.
More information about the Python-list
mailing list