Section 6.16 of the language refers states that expressions are evaluated left to right, so yes a()
will always execute before b()
, doesn't matter which operand is between them:
Python evaluates expressions from left to right. Notice that while
evaluating an assignment, the right-hand side is evaluated before the
left-hand side.
In the following lines, expressions will be evaluated in the
arithmetic order of their suffixes:
expr1, expr2, expr3, expr4
(expr1, expr2, expr3, expr4)
{expr1: expr2, expr3: expr4}
expr1 + expr2 * (expr3 - expr4)
expr1(expr2, expr3, *expr4, **expr5)
expr3, expr4 = expr1, expr2
Whether or not b()
is executed at all depends on the operand type.
For boolean operands, as described by @Eureka in their answer, the answer is that b()
is evaluated only if necessary to compute the result (i.e. the operand will "short circuit"). For other operands b()
will be evaluated unless a()
raises an exception.