(no) fast boolean evaluation ?

Ian Clark iclark at mail.ewu.edu
Thu Aug 2 18:55:44 EDT 2007


Stef Mientki wrote:
> hello,
> 
> 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 ?
> 
> thanks,
> Stef Mientki

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?

Ian




More information about the Python-list mailing list