(no) fast boolean evaluation ?

John Machin sjmachin at lexicon.net
Fri Aug 3 01:30:39 CEST 2007


On Aug 3, 9:19 am, "Evan Klitzke" <e... at yelp.com> wrote:
> On 8/2/07, Stef Mientki <S.Mientki-nos... at mailbox.kun.nl> 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 ?
>
> This is standard behavior in every language I've ever encountered. If
> you are evaluating an and/or with side effects and you need both side
> effects to occur, you can trivially write functions implementing this
> behavior, e.g.
>

If each operand is of type bool (or, more generally,
isinstance(operand, int) is true), you could trivially use the & and |
operators.




More information about the Python-list mailing list