4
Functions
Functions are how programs stay readable past fifty lines. Today you write your own, learn Python's flexible argument rules, and meet comprehensions.
Lessons
- 1 Defining Functions Wrap behaviour in a name, hand it inputs, get a value back — and learn why returning beats printing. functions return docstrings
- 2 Arguments in Depth Positional and keyword arguments, *args and **kwargs, and how mutable arguments can surprise you. functions arguments kwargs
- 3 Scope & Lambdas Where names live, why functions cannot see each other's variables, and the one-line functions you pass to sort(). scope lambda sorting
- 4 Comprehensions Transform and filter a collection in one readable line — the construct that makes Python look like Python. comprehensions lists dictionaries