Skip to main content
The Python interpreter is your gateway to running Python code. This guide covers how to start the interpreter, pass arguments, and understand its interactive mode.

Invoking the Interpreter

The Python interpreter is usually installed as /usr/local/bin/python3.15 on Unix systems. You can start it by typing:
On Windows, if you’ve installed Python from the Microsoft Store, use:
Or with the py launcher:

Exiting the Interpreter

To exit the interpreter:
  • Unix/Linux: Press Ctrl-D
  • Windows: Press Ctrl-Z then Enter
  • All platforms: Type quit()

Command Line Editing

The interpreter supports:
  • Interactive line editing
  • History substitution
  • Code completion on most systems
Test if command line editing works by typing a word and pressing the Left arrow key. If the cursor moves, editing is enabled.

Running Python Scripts

You can run Python code in several ways:

Execute a File

Execute a Command

Since Python statements often contain spaces or special characters, quote the entire command.

Execute a Module

Interactive Mode After Script

Run a script and then enter interactive mode:

Argument Passing

When you run a Python script, command-line arguments are available in sys.argv:
Special cases:
  • No script: sys.argv[0] is an empty string
  • With -c: sys.argv[0] is '-c'
  • With -m: sys.argv[0] is the full module name

Interactive Mode

When you start the interpreter without a script, it enters interactive mode:

Prompts

  • Primary prompt (>>>): Ready for a new statement
  • Secondary prompt (...): Continuation of a multi-line statement

Source Code Encoding

By default, Python source files are treated as UTF-8 encoded. This allows using characters from most languages:

Declaring a Different Encoding

To use a different encoding, add a special comment as the first line:
Example for Windows-1252:

With a Shebang Line

If your script starts with a shebang, the encoding goes on the second line:
For portable code, stick to UTF-8 encoding and ASCII identifiers even if you can use non-ASCII characters in strings and comments.

Next Steps

Now that you know how to invoke the interpreter, let’s explore Python basics in the Introduction to Python.