Python Get Started

Before you can run Python programs you need the interpreter installed, and it helps to know the few ways you can actually run your code.

Do you already have Python?

Many computers, especially those running macOS or Linux, come with Python already installed. You can check by opening a terminal (Command Prompt or PowerShell on Windows) and asking for the version number. If a version is printed, Python is ready to use.

Example

python --version

On some systems the command is written as python3 instead of python. If the first command reports an error, try the second one.

Installing Python

If Python is not installed, or the version is old, download the latest release from the official website at python.org. The installers walk you through the process. On Windows, be sure to tick the box labelled "Add Python to PATH" during setup, so the interpreter can be found from any terminal window.

Ways to run your code

MethodBest for
Interactive shell (REPL)Trying out single lines and quick experiments
Saving a .py file and running itFull programs you want to keep and reuse
A code editor or IDELarger projects with many files and helpful tooling

The interactive shell, often called the REPL (Read-Eval-Print Loop), lets you type Python one line at a time and see each result immediately. Start it by typing python (or python3) with nothing after it. The >>> symbol is the prompt inviting you to type.

Example

>>> print("Hello from the shell")
Hello from the shell
>>> 3 + 4
7

For anything longer than a couple of lines, save your code in a plain text file ending in .py and run it from the terminal. Suppose you have a file named hello.py containing a print statement; you run it like this:

Example

python hello.py
Note: To leave the interactive shell, type exit() and press Enter, or press Ctrl+Z then Enter on Windows (Ctrl+D on macOS and Linux).

Exercise: Python Get Started

What file extension is standard for Python script files?