Learn Python and related technologies

Visualize code execution step by step.


1
#Execution of generator functions
2
def func():
3
    print('Hello, World!')
4
    yield 1
5
    print('You are at Pynerds')
6
    yield 2
7
    print('Enjoy Your stay')
8
    yield 3
9
10
gen = func()
11
print(next(gen))
12
print('....................')
13
print(next(gen))
14
print('....................')
15
print(next(gen))
0  of

source: www.pynerds.com
just executed line
Caller Line
 
                
Global

About the Visualizer

Most people are visual learners, this means that they will understand something more clearly when it is presented visually rather than in purely written form. This motivated me to create this tool to help beginners to quickly understand the basic concepts of Python and programming in general. 

The visualizer allows you to view step by step how a given code snippet is executed by the interpreter. In each step the line that was executed is highlighted and its output(if any)  is displayed together with the scope details. 

How to use the visualizer

To visualize a code snippet, you will need to:

  1. Click the edit snippet button at the top left of the snippet area, or directly open the editor here. After you have edited the snippet, click the visualize button and you will be brought back to the visualizer with the edited snippet.
  2. To run the visualization, you can use two approaches:
    • automated approach - By clicking the run/play button at the top of the snippet. This way the visualization will run on its own until complete or until you press the pause button. The automated approach is especially useful if the snippet has repetitive steps such as in case with loops.
    • manual approach - Using the four navigation buttons at the bottom of the snippet i.e first, prev, next and last.
  3. After each line is executed, its output(if any) is displayed in the output panel and the scope panel is updated to reflect any changes due to that line.

This tool is mostly useful when used with small,  concise and self-contained code snippets. Its purpose is to demonstrate the operation of basic python programs and concepts. It is not meant to be used with complex programs with many steps or those that takes too long to run. It is also not for professional debugging.

How to save the snippet after visualizing

If you want to save a snippet, click the share link button and the snippet will be permanently stored so that it will be accessible with the link that will be generated. You can then copy the generated link using the copy link button.