Run Python Scripts and the Interactive REPL
Run a saved script
A script is a file of Python source code, usually with the .py extension. If Python 3 is installed, save the following line in greeting.py in a folder you can access. Open a terminal in that folder.
At the terminal prompt, run python3 greeting.py if python3 starts Python 3 on your system. On Windows with the Python launcher, py -3 greeting.py is another option; some installations use python greeting.py. Use the command that actually starts Python 3. The terminal should display Welcome to Python. These are shell commands, not Python source.
Use the interactive interpreter
Starting the interpreter without a filename normally opens the interactive REPL (read–evaluate–print loop). It accepts a command, evaluates it and displays results when appropriate. Here is an illustrative transcript; >>> is the prompt, not something to type.
>>> print("Tea ready")Tea ready>>>Type only the Python instruction after the prompt. For a standard interactive Python session, quit() exits; a browser learning editor may provide its own controls.
A saved script makes the same instructions easy to rerun. The REPL is convenient for trying one instruction at a time. If the shell cannot find your Python command, check the installation and the command name rather than editing the print line. If you see >>>, you are already in Python, so do not type a shell command there.
Practice switching environments
Run a saved file with the message Practice complete, then enter the same instruction interactively. Compare the output, not the prompt. If you only have a browser editor, run the source there and read the transcript as an illustration.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Scripts and interactive commands
Check your understanding of running scripts and repl.
What is a Python script?
In a REPL transcript, what does >>> mean?
You see >>> and want to run the shell command python3 greeting.py. What should you do?