(no) fast boolean evaluation ?
infocat at earthlink.net
Sat Aug 4 06:49:12 CEST 2007
Ian Clark wrote:
> Stef Mientki wrote:
>> I discovered that boolean evaluation in Python is done "fast"
>> (as soon as the condition is ok, the rest of the expression is ignored).
>> Is this standard behavior or is there a compiler switch to turn it
>> on/off ?
> It's called short circuit evaluation and as far as I know it's standard
> in most all languages. This only occurs if a conditional evaluates to
> True and the only other operators that still need to be evaluated are
> 'or's or the condition evaluates to False and all the other operators
> are 'and's. The reason is those other operators will never change the
> outcome: True or'd with any number of False's will still be True and
> False and'ed to any number of Trues will still be False.
> My question would be why would you *not* want this?
Pascal, and apparently Fortran, do not use short-circuit evaluation. I
remember learning this gotcha in my seventh-grade Pascal class (plus I
just googled it to make sure my memory was correct!).
More information about the Python-list