Evaluating conditional expressions

Python imposes strict ordering on expressions; the notable exceptions are the short-circuit operators, and and or. It imposes strict ordering on statement evaluation. This makes it challenging to find optimizations because they would break the strict evaluation order.

Evaluating condition expressions is one way in which we can experiment with non-strict ordering of statements. The if, elif, and else Python statements are evaluated in a strict order from first to last. Ideally, an optimizing language may relax this rule so that a compiler can find a faster order for evaluating the conditional expressions. This allows us to write the expressions in an order that makes sense to a reader, and lets the compiler ...

Get Functional Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.