See how Python runs

Python Visualizer: Step Through Code and Watch Variables

Run any Python program one line at a time. The editor highlights the line that runs next and shows every variable and its value, so you can see exactly what your code does and where it goes wrong.

How to visualize Python code

  1. Open the Python editor with your own code, or with one of the examples below.
  2. Click beside a line number to set a breakpoint where you want to start watching.
  3. Select Debug. The program runs and pauses on that line, and the line is highlighted.
  4. Read the Variables panel to see every value at this moment, and the Call Stack to see which function you are in.
  5. Use Step Over to run the next line, Step Into to follow a function call, and Continue to jump to the next breakpoint. Watch the values change after each step.

Why visualize your code?

  • Understand loopsSee each iteration of a for or while loop and the values it produces.
  • Follow recursionWatch the call stack grow with every recursive call and shrink as each one returns.
  • Find bugs fasterSpot the exact line where a variable gets the wrong value, without adding print statements.
  • Learn algorithmsSorting and searching algorithms become clear when you see every comparison and swap.
  • Any Python codeVisualize your own programs, homework or interview practice, not just prepared examples.
  • AI explanationsAsk the AI to explain a confusing line or fix an error, right in the editor.

Example: watch a list being sorted

Set a breakpoint on the if items[i] > items[i + 1] line and select Debug. Each time you press Continue, the Variables panel shows the list after the latest swap, so you can watch the largest values move to the end.

bubble_sort.py
bubble_sort.py
def bubble_sort(values):
    items = list(values)
    for end in range(len(items) - 1, 0, -1):
        for i in range(end):
            # Set a breakpoint on the next line and watch items change.
            if items[i] > items[i + 1]:
                items[i], items[i + 1] = items[i + 1], items[i]
    return items


print(bubble_sort([5, 2, 9, 1]))

Example: follow a recursive function

Set a breakpoint on the if n <= 1 line and use Step Into. The Call Stack shows one factorial call for each value of n, and you can watch them return one by one.

factorial.py
factorial.py
def factorial(n):
    # Step Into each call and watch the call stack grow, then shrink.
    if n <= 1:
        return 1
    return n * factorial(n - 1)


print(factorial(4))

Algorithm lessons with an animated view

These lessons also show each step of the algorithm as an animation next to the code.

Frequently asked questions

What does the Python visualizer show?

It runs your program one line at a time, highlights the line that runs next and shows every variable and its current value, together with the call stack of functions.

Do I need to install anything?

No. The visualizer runs in your browser or on our server, so you can step through Python code on any computer without installing Python.

Can I visualize my own code?

Yes. Paste or write any Python program in the editor, set a breakpoint beside a line number and select Debug.

Is it good for learning algorithms?

Yes. Stepping through a loop or a recursive function and watching the values change is one of the best ways to understand how an algorithm works. The algorithm lessons below also include an animated view.

Is it free?

Yes. The Python visualizer and editor are free and do not need an account.