Last in, first out
Think of a stack of plates: you put a new plate on top, and you take from the top. You never slide one out of the middle.
When a program calls a function, the computer pushes a stack frame (locals and where to return). A nested call pushes another frame on top. When a function finishes, its frame pops — the caller underneath becomes active again. That is LIFO in action.
def add(a, b): return a + b def double(n): return add(n, n) print(double(4)) # → 8
double waits while add runs on top of the call stack.
Run the simulation
First push and pop values. Then watch stack frames grow and shrink as nested calls run.
Push and pop freely
Build your own value stack. Push adds on top; pop removes from the top.
Stack mental model
Restrict access to one end — values and call frames both use LIFO.
Last in, first out
Pop always returns the most recently pushed value or frame.
Call → push, return → pop
Each call adds a frame with locals. The return pops that frame and resumes the caller.