Caffeinated Coder
Book an appointment
Lesson 27 · Under the hood

Bytecode and the CPython VM

CPython runs your code in two stages. First the compiler turns the source into bytecode: small, simple instructions stored in a code object. Then a virtual machine runs those instructions one at a time, pushing and popping values on a stack. Follow a three-line program, bump.py, through both stages, read its bytecode with the dis module, and see how the VM speeds up code that runs often.

14 min11 steps5 questionsAdvanced
Fig 27 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.