Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6070 > unrolled thread

Re: and becomes or and or becomes and

Started by"Colin J. Williams" <cjw@ncf.ca>
First post2011-05-23 08:20 -0400
Last post2011-05-23 08:20 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: and becomes or and or becomes and "Colin J. Williams" <cjw@ncf.ca> - 2011-05-23 08:20 -0400

#6070 — Re: and becomes or and or becomes and

From"Colin J. Williams" <cjw@ncf.ca>
Date2011-05-23 08:20 -0400
SubjectRe: and becomes or and or becomes and
Message-ID<mailman.1974.1306153236.9059.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web