Velocity Reviews > compound conditional statements

# compound conditional statements

beliavsky@aol.com
Guest
Posts: n/a

 09-15-2003
If I have code

if (aa or bb): print "true",

does Python evaluate aa and bb in any particular order? Can I assume that if
aa is true, bb will not be evaluated?

Jeff Epler
Guest
Posts: n/a

 09-15-2003
On Mon, Sep 15, 2003 at 02:31:06PM -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> If I have code
>
> if (aa or bb): print "true",
>
> does Python evaluate aa and bb in any particular order? Can I assume that if
> aa is true, bb will not be evaluated?

Yes.

http://python.org/doc/ref/Booleans.html
The expression x or y first evaluates x; if x is true, its value is
returned; otherwise, y is evaluated and the resulting value is
returned.

Jeff

Jeremy Yallop
Guest
Posts: n/a

 09-15-2003
(E-Mail Removed) wrote:
> If I have code
>
> if (aa or bb): print "true",
>
> does Python evaluate aa and bb in any particular order?

Yes. `aa' is evaluated first. If it is true, `bb' is not evaluated
and the value of `aa' is the value of the expreesion. If `aa' is
false, the value of `bb' is the value of the expression.

> Can I assume that if aa is true, bb will not be evaluated?

Yes.

Jeremy.

Steve Holden
Guest
Posts: n/a

 09-15-2003
<(E-Mail Removed)> wrote ...
> If I have code
>
> if (aa or bb): print "true",
>
> does Python evaluate aa and bb in any particular order? Can I assume that

if
> aa is true, bb will not be evaluated?

Yes. Both "and" and "or" are specifcally short-circuiting.

regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/