Interactive Sessions

If no program name is given and the standard input to the interpreter is an interactive terminal, Python starts in interactive mode. In this mode, a banner message is printed and the user is presented with a prompt. In addition, the interpreter evaluates the script contained in the PYTHONSTARTUP environment variable (if set). This script is evaluated as if it’s part of the input program (that is, it isn’t loaded using an import statement). One application of this script might be to read a user configuration file such as .pythonrc.

When interactive input is being accepted, two user prompts appear. The >>> prompt appears at the beginning of a new statement; the ... prompt indicates a statement continuation. For example:

Get Python: Essential Reference, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.