Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6070
| From | "Colin J. Williams" <cjw@ncf.ca> |
|---|---|
| Subject | Re: and becomes or and or becomes and |
| Date | 2011-05-23 08:20 -0400 |
| References | <4DD96297.5010909@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1974.1306153236.9059.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: and becomes or and or becomes and "Colin J. Williams" <cjw@ncf.ca> - 2011-05-23 08:20 -0400
csiph-web