Python visualizer
Press Visualize to replay your Python code one line at a time and see the call stack and every variable at each step. Real CPython, running privately in your browser.
def fact(n):
if n <= 1:
return 1
return n * fact(n - 1)
print(fact(4))
How to read the step viewer
- Highlighted line: the line Python is about to run.
- Call stack: the functions currently running, innermost last. In the factorial example, watch
factstack up four deep, then unwind as each call returns. - Variables: the local names in the current frame. A highlighted value just changed on this step.
- Output: everything printed so far, so you can see exactly which line produced which output.
Good things to visualize
Off-by-one loops, recursion, aliasing (two names pointing at the same list), and algorithms like binary search, where the values of lo, mid and hi at each step tell the whole story. The examples menu has one of each.
Just want the output? Use the online Python compiler; the same code works there with numpy, pandas and matplotlib. To find mistakes without running anything, try the Python code checker. Comprehensions are easier with the dedicated list comprehension explainer.
Frequently asked questions
What is a Python visualizer?
A tool that runs your program one step at a time and shows what Python is doing at each step: which line is executing, which functions are on the call stack, and the current value of every variable. It is the quickest way to see why a loop or a recursive function behaves the way it does.
Is this like Python Tutor?
It serves the same purpose as Python Tutor (pythontutor.com): step forwards and backwards through real Python execution. The difference is where it runs. Here CPython runs inside your browser through WebAssembly, so nothing is sent to a server and there is no queue.
How many steps can it record?
Up to 400 line, call and return events per run. That covers typical teaching examples and small algorithms; for longer programs, shrink the input (for example, a list of 6 items instead of 1,000).
Can it visualize input() and imports?
Yes. Type stdin lines into the input box before pressing Visualize. Standard-library imports work; the tracer only records lines in your own file, not inside library code.
How do I move through the steps?
Use the Prev / Next buttons, drag the slider, or focus the viewer and press the left and right arrow keys. Variables whose value just changed are highlighted.