Conditional Expressions and the Operator Module

Functional programming emphasizes lazy or non-strict ordering of operations. The idea is to allow the compiler or runtime to do as little work as possible to compute the answer. Python tends to impose strict ordering on evaluations, which could be inefficient.

The Python if, elif, and else statements enforce a strict ordering on the evaluation of the conditions. In this chapter, we'll look at ways we can, to an extent, free ourselves from the strict ordering, and develop a limited kind of non-strict conditional statement. It's not clear whether this is helpful, but it will show some alternative ways to express an algorithm in a somewhat more functional style.

In the previous chapters, we looked ...

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.