📜 Functions: name your recipes
Why: Name your recipes and reuse them with def.
Unlocks: The capstone project — and clean code forever.
In the recipes lesson you learned that an algorithm is a precise recipe. A function is a recipe you write once, give a name, and cook whenever you want by saying its name. You've been using functions all along — print, input, len are recipes someone else wrote.
def (define) writes your own:
Recipes take ingredients (parameters) and can hand back a result (return):
Your turn. Write a recipe called greet that takes a name and prints Hello, plus the name:
What happens when Python reads a def block?
What's the difference between print and return inside a function?
🔍 Go deeper: watch the machine jump into a function and back, call stack and all → PyDebug: Functions.