Visualize code execution for Python, Java, C, C++, and JavaScript

This is the only tool that lets you debug code step-by-step and get personalized AI tutoring.

Please wait ... your code is running (up to 10 seconds)
Write code in

NEW: teachers can get free access to ad-free/AI-free mode
Ads keep this site free for everyone. Donate to get ad-free and faster AI.
(teachers get free access)

Python Tutor is designed to imitate what an instructor in an introductory programming class draws on the blackboard:

Image

Instructors use it as a teaching tool, and students use it to visually understand code examples and interactively debug their programming assignments.

Quick links:

Demo

The screenshot below shows how a typical user (either an instructor or a student) would interact with it:

Image

  • (1) Go to pythontutor.com and select a language. Here the user chose Java and wrote code to recursively create a LinkedList.
  • (2) Press 'Visualize' to run the code. This code ran for 46 steps, where each step is one executed line of code. Go to any step (2a) and see what line of code was being run at that step (2b).
  • (3) See the frames of all functions/methods on the stack at this step, each of which shows its local variables. Here at step 41 we see main() along with 4 recursive calls to init().
  • (4) See all objects on the heap at the current step. Here it shows a LinkedList instance with first and last fields pointing to its first and last Node instances, respectively. Each Node has a numerical value and a next pointer.
  • (5) See what has been printed up to this step. Here the print statement in the Node constructor (line 5) has run 3 times.

The user can navigate forwards and backwards through all execution steps, and the visualization changes to match the run-time state of the stack and heap at each step. In this example, the user would see their custom LinkedList data structure getting incrementally built up one Node at a time via recursive calls to init() until the base case is reached when n==0.

Language Support

Despite its name, Python Tutor is also a widely-used web-based visualizer for Java that helps students to understand and debug their code. It visualizes the majority of object-oriented programming concepts taught in introductory college courses (e.g., CS1 and CS2), high school AP Computer Science, and intermediate-level Java programming.

Python Tutor is also a widely-used web-based visualizer for C and C++ meant to help students in introductory and intermediate-level courses. It uses Valgrind to perform memory-safe run-time traversal of data structures, which lets it display data more accurately than gdb or printf debugging. For instance, it can precisely visualize critical concepts such as pointers, uninitialized memory, out-of-bounds errors, nested arrays/structs/unions, type punning, and bit manipulation.

Lastly, it also supports visualizing standalone JavaScript execution, but not web frontend code that does DOM manipulation on webpages.

Reporting Bugs

The issue you're encountering is likely listed in this document. If you're sure it's not, use the "Generate permanent link" button to make a URL of your code. Describe the expected behavior when running that code on your computer and how it differs from Python Tutor, then fill out this Google Form to report your bug or security issue.

  • This form is not for requests or questions about desired features; it is only for reproducible bug reports and private disclosures of security-related issues.
  • If you don't get a reply, assume your issue will not be addressed. Please do not submit duplicate issues in the form.
  • There is no support for Python Tutor visualizations that are embedded in other people's websites. Contact those site owners for help on how to use their sites.