boolean operations on sets

Alex Martelli aleax at mac.com
Tue Aug 7 04:46:44 CEST 2007


Michael J. Fromberger <Michael.J.Fromberger at Clothing.Dartmouth.EDU>
wrote:
   ...
> Also, it is a common behaviour in many programming languages for logical
> connectives to both short-circuit and yield their values, so I'd argue
> that most programmers are proabably accustomed to it.  The && and || 
> operators of C and its descendants also behave in this manner, as do the

Untrue, alas...:

brain:~ alex$ cat a.c
#include <stdio.h>

int main()
{
    printf("%d\n", 23 && 45);
    return 0;
}
brain:~ alex$ gcc a.c
brain:~ alex$ ./a.out 
1

In C, && and || _do_ "short circuit", BUT they always return 0 or 1,
*NOT* "yield their values" (interpreted as "return the false or true
value of either operand", as in Python).


Alex
  



More information about the Python-list mailing list