How to use the Python Code Visualizer
- 1. Paste a short programLoops, functions, lists, dicts and recursion all work.
- 2. Press VisualizePython runs your code once and records every step.
- 3. Step throughMove forward and back to see the line, variables and output at each step.
What each step shows
For every step the visualizer highlights the line that is about to run, lists each active function call (frame) with its local variables, and shows everything printed so far. When a function finishes, the step says what it returned and the line turns green.
It works by running your code in real Python (Pyodide) with Python's own tracing hook, sys.settrace. That hook is called before each line, so the recorded values are exactly what Python had at that moment, not a guess. Up to 1,000 steps are recorded, which is plenty for teaching-sized programs.
Worked example: a loop and a recursive call
The starter code adds up [3, 1, 2] in a loop and then calls factorial(3). Step through and you will see:
totalgoes 0 → 3 → 4 → 6 asxtakes each value in the list.factorial(3)callsfactorial(2), which callsfactorial(1). Three frames are stacked, each with its ownn.- factorial(1) returns 1, then factorial(2) returns 2, then factorial(3) returns 6, unwinding the stack.
The final output is total = 6 and 3! = 6. Seeing separate frames for each call is the clearest way to understand recursion, and the same view helps you find off-by-one errors in loops.
Keep programs under 120 lines. Values longer than 90 characters are shortened, modules are hidden, and functions show as "function name".
Frequently asked questions
Does it work with input()?
Yes. Type the values in the Input box separated by a | sign, and each input() call takes the next one.
Why did it stop at 1,000 steps?
To keep the page fast. Shrink loop counts, for example range(5) instead of range(1000), to see the whole run.
Is my code uploaded?
No. Python runs inside your browser. The engine itself loads from the public jsDelivr CDN.
Is the visualizer free?
Yes, it is free. The first time you press Visualize, we ask for your name and WhatsApp number once. After that, all Uncodemy tools open without it.