Functions let you name a chunk of work once and reuse it everywhere — with values flowing in and out.
1 def Defines It
def greet(name): stores the function — the body only runs when you call it.
2 Parameters In
Arguments like "Ada" land in the parameters, which are local to each call.
3 return Sends Back
return hands a value to the caller and ends the call immediately.
4 lambda = One-Liner
lambda n: n * 2 is a tiny nameless function built from a single expression.
Package your logic
def Defines It1def greet(name): stores the function — the body only runs when you call it. Parameters In2Arguments like "Ada" land in the parameters, which are local to each call. return Sends Back3return hands a value to the caller and ends the call immediately. lambda = One-Liner4lambda n: n * 2 is a tiny nameless function built from a single expression.
4 building blocks make up Package your logic
Press Run and follow add(2, 3) from the call site to the returned value.
Watch the scope switch from main into a function and back — then see a lambda do the same in one line.
maindef stores the function double — its body waits for a call.
Memory
no variables yet — press play
Console
output appears as the program runs…
Every call opens a frame on the call stack; return closes it and delivers the value home.
process decision input / output start / end Click a term, then click its role in a call.
5 conceptsTap a card to expand ?defdrops into place
?returndrops into place
?lambdadrops into place
?parameterdrops into place
?argumentdrops into place
A def and a lambda walk into a program — and one call nests inside another.
Your predicted output — one line per console line
Hint: Calls nest: the inner call triple(2) runs first, and its value 6 is what square receives.
01def stores a function; the call opens a fresh frame with its own locals.
02return hands the value back and pops the frame immediately.
03Locals vanish when the call ends — frames do not keep leftovers.
04lambda n: n * 2 is a compact def for one-expression helpers.
05A call is an expression: it is replaced by whatever it returns.