CoursePython from Scratch to Intermediate · Module 6: Functions · part 42 of 75
Part 42 · Module 6: Functions

Lesson 3: Where names live, and functions as values

15 min read·14 Oct 2026
Module 6 · Lesson 3 · About 45 minutes · Needs: Module 6 Lessons 1 and 2 (def, return, parameters), Module 5 (lists, dictionaries, comprehensions)

The situation

Amira likes the functions from Lessons 1 and 2: days_late(21, 44) says Ben is 9 days late every time. Now she wants the overdue loans in order, most owed first, so she knows whom to call. And she wants proof that the fee rule is right before it touches the charity jar.

That needs three ideas: which names a function can see, how to hand one function to another, and how to check a function in one line.

OVERDUE, IN SLICE ORDER L04 Jonah 300p L13 Ben 180p L21 Kwame 80p L23 Lena 20p sorted(...) key=, reverse=True CALL LIST 1. Jonah 300p 2. Ben 180p 3. Kwame 80p 4. Lena 20p then assert checks the fee rule
Amira wants the four overdue loans (blue) turned into a call list with the most owed first (green), and proof that the fee rule behind it is right.

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.