(no) fast boolean evaluation ?
Evan Klitzke
evan at yelp.com
Thu Aug 2 19:19:24 EDT 2007
On 8/2/07, Stef Mientki <S.Mientki-nospam 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.
def a():
print 'foo'
def b():
print 'bar'
def my_and(lh, rh):
return a and b
Then my_and(a(), b()) will evaluate both a and b and print both foo
and bar even though a() is False.
--
Evan Klitzke <evan at yelp.com>
More information about the Python-list
mailing list