(no) fast boolean evaluation ?

John Machin sjmachin at lexicon.net
Fri Aug 3 01:22:59 CEST 2007


On Aug 3, 8:55 am, Ian Clark <icl... at mail.ewu.edu> wrote:
> 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?
>
>

Why? Perhaps under some compound condition like this:

(you_are_confused and/or
function_returns_bool_but_has__side_effects())




More information about the Python-list mailing list