Functional programming pursues short, reliable, maintainable code by keeping functions short, treating data as immutable, and avoiding tracked state. Functions transform inputs into outputs rather than modifying existing values, which can reduce test paths and debugging effort while feeling unnatural when programs must model changing real-world data. section 7.0
The approach rests on a few practical habits:
- Keep functions short so they are easier to understand, test, and maintain. section 7.0
- Avoid modifying data inside functions; create new values when a changed result is needed. section 7.0
- Pass functions as arguments and use them to filter or transform iterable inputs. section 7.5
- Prefer comprehensions for many Python transformations, while recognizing that map can handle multiple iterables conveniently. section 7.5
Transform without changing the input
A comprehension selects and transforms even numbers in one expression: [x*x for x in range(10) if x%2 == 0] The input range is not updated; the expression produces a new sequence of squared values. The same pipeline can be expressed with map and filter when named functions or multiple iterables make that form clearer. section 7.5
Table 7.1 What you need to know (view table figure)
| Returns |
|||
Use the reference table to compare list, dictionary, and set comprehensions with input and string-transformation tools. section 7.0


















