Python Visualizer
Run your code one line at a time and watch its variables and objects change.
Algorithm animations
Recursion
How to read it
The yellow arrow marks the line Python runs next, and the dimmer line is the one that just ran. Frames, on the left, hold the variables: the global frame for your program, plus one frame for every function call in progress.
Numbers and text sit right next to their names. Lists, dicts, tuples, sets and objects of your own classes appear on the right, and a blue arrow runs from every name that refers to them. Two arrows to one box means two names share one object.
Good things to try
- Why changing one list changed another ("Two names, one list").
- How a function gets its own variables ("A function call").
- How recursion stacks up frames and returns through them ("Recursion").
- Your own homework, or any of the programs with output.
Questions
What does a Python visualizer show?
It runs your program and records Python's state at every line: which line runs next, the variables in each function call, and the lists, dicts and objects they refer to. You then step forward and back through that recording.
Is this like Python Tutor?
It follows the same idea: frames on one side, objects on the other, and arrows for references. It also works on phones.
Why do two variables sometimes point to the same list?
In Python, b = a does not copy a list; both names refer to the same object, so a change through b shows up in a. Load the "Two names, one list" example and step through it to watch it happen, then see how a.copy() makes a separate list.
Are there limits?
The visualizer records up to 1,000 steps and shows up to 40 items per list or dict, so keep examples small. input() does not work here: put the values in variables instead.