Chapter 13. 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 at a number of higher-order functions. In some cases, we used these higher-order functions to apply fairly sophisticated functions to collections of data. In other cases, we applied simple functions to collections of data.
Indeed, in many cases...