Learn how to run Python code?

You can execute Python code from the terminal or from a Python IDE. An IDE is a graphical environment that assitsts in software development.

If you are new to Python, I recommend this course:

How to run Python

All Python programs are written in code, text files with lots of instructions. These are saved with the extension .py.

A program made in Python can be one or more .py files.
python program

To run a Python program, you need to have Python installed. Start the terminal.
In the terminal, type the command below to test if Python is installed

python --version

Python installed?

Open a terminal and enter the directory of your program. The directory may contain more than one python (.py) file.

cd your_app_directory

In the terminal type:

python file.py

where file.py is the name of your program. If you have more than one file, the main program is often the name of the program itself;

Use an IDE

Sometimes an easier way to execute Python programs is using a Python IDE. What is an IDE?

An IDE is a tool that assists in software development. Its a software program that has many features like code coloring (syntax highlighting), file navigation, quick search and much more.

In most IDEs, there’s a play button that instantly runs the Python program. In other words, in a Python IDE, you simply press the ‘play’ button.

pycharm toolbar

The image above shows the header of the program PyCharm, a Python IDE. The green play button can be used to start a program.

Download exercises