Concepts / Using the Python Interactive Shell

Using the Python Interactive Shell

Open the Windows command line by clicking Start, then Run, typing cmd, and pressing Enter

  • Programming

From Start Menu to Terminal

The Python interactive shell gives you immediate access to a Python prompt where you can execute commands, test code snippets, and interact with Python. On Windows, you begin outside Python by opening the Windows command line terminal.

clicktypepress EnterStartRuncmdCommand prompt
What sequence of actions opens a Windows command-line window?
  1. Click the Start button.
  2. Click Run.
  3. Type cmd in the Run dialog.
  4. Press Enter.
  5. Wait for the Windows command prompt window to open.

Launching Python from Windows

When the command prompt window opens, it provides a text-based interface for interacting with the Windows operating system. At this point, you are in the Windows command line environment, not yet in Python. Type python at the command prompt and press Enter. Windows then finds and executes the Python interpreter, provided Python is installed and the PATH variable is properly configured.

type python and press EnterlaunchesdisplaysUserWindows terminalPython interpreter>>>
What command is entered, and what happens when Windows starts Python?

Launching Python

You have opened the Windows command prompt and want to enter the Python interactive shell.

Enter the launch command: At the Windows command prompt, type python and press Enter.

Wait for interpreter startup: Windows launches the Python interpreter.

Inspect the result: Python displays version information and then shows the >>> prompt.

The >>> prompt indicates that Python is ready to accept Python commands.

Recognizing the Python Prompt

Successful startup is visible in the terminal. Python displays version information, followed by three greater-than symbols: >>>. The exact version number can differ according to the Python version installed, but the version information and the >>> prompt are the important signs to look for.

python and Enterready for Python codeWindows commandpromptC:\Users\YourName>Python prompt>>>Version information
How does the terminal change when Python starts successfully, and which prompt confirms that it is ready?
EnvironmentVisible promptWhat it expects
Windows command lineSomething like C:\Users\YourName>Windows commands
Python interactive shell>>>Python code

Moving Between Environments

Running Python from the Windows command line creates a hierarchy of environments. The Windows operating system is the bottom layer. The command-line terminal provides a text-based way to communicate with that operating system. When you type python, the terminal launches the Python interpreter. The >>> prompt shows that you are now working inside that interpreter.

Commands belong to the environment whose prompt is visible. A Windows command-line prompt expects Windows commands. The Python prompt expects Python code. A command that works in one environment may not work in the other, so check the prompt before entering an instruction.

  1. Begin at the Windows command prompt.
  2. Type python and press Enter.
  3. Confirm that version information appears.
  4. Confirm that the prompt changes to >>>.
  5. Enter Python commands only while >>> is visible.
  6. To return to Windows, type exit() at the Python prompt and press Enter.

Mistakes with the Two Prompts

  • Assuming the Windows command prompt is already the Python shell.

    Opening the terminal only places you in the Windows command-line environment. Python has not started yet.

    Fix: Type python at the Windows command prompt and press Enter, then look for version information and >>>.

  • Treating >>> as a Windows command prompt.

    The >>> prompt belongs to the Python interpreter and expects Python code.

    Fix: Use Python code while >>> is visible. Type exit() and press Enter when you need to return to the Windows command line.

  • Failing to verify startup.

    The visible version information and >>> prompt are the signs that the interpreter has started and is waiting for input.

    Fix: Check for both version information and the >>> prompt before entering Python commands.

Guided Terminal Check

EASY

Practice the complete transition on a Windows system: open the Run dialog from Start, enter cmd, press Enter, type python at the Windows command prompt, and press Enter. Before you do anything else, identify which prompt is visible. Then state whether you are in the Windows command line or the Python interactive shell, and explain what the visible prompt tells you.

Hints
  • The Windows command line prompt looks something like C:\Users\YourName>.
  • The Python interactive shell displays version information and ends with >>>.
  • The >>> prompt means that Python is ready to accept Python code.

Shell Startup Checklist

  1. Open the Windows command line through Start, Run, cmd, and Enter.
  2. At the Windows command prompt, type python and press Enter.
  3. Verify startup by looking for Python version information and the >>> prompt.
  4. Remember that the Windows command prompt expects Windows commands, while >>> expects Python code.
  5. Use exit() at the Python prompt to return to the Windows command line.

Key Takeaways

  • The Windows Run dialog provides a quick way to open the command-line terminal.
  • Typing python at the Windows command prompt launches the Python interpreter when Python is installed and PATH is properly configured.
  • Version information followed by >>> confirms that Python is running and ready for input.
  • The Windows command prompt and the Python prompt are different environments with different expected commands.
  • Typing exit() at >>> returns you to the Windows command line.