Using the Python Interactive Shell
Windows then finds and executes the Python interpreter, provided Python is installed and the PATH variable is properly configured.
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.
- 1Click the Start button.
- 2Click Run.
- 3Type cmd in the Run dialog.
- 4Press Enter.
- 5Wait 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.
Launching Python
You have opened the Windows command prompt and want to enter the Python interactive shell.
- 1Enter the launch command
At the Windows command prompt, type python and press Enter.
- 2Wait for interpreter startup
Windows launches the Python interpreter.
- 3Inspect 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.
| Environment | Visible prompt | What it expects |
|---|---|---|
| Windows command line | Something like C:\Users\YourName> | Windows commands |
| Python interactive shell | >>> | Python code |
The prompt identifies which environment is currently active.
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.
- 1Begin at the Windows command prompt.
- 2Type python and press Enter.
- 3Confirm that version information appears.
- 4Confirm that the prompt changes to >>>.
- 5Enter Python commands only while >>> is visible.
- 6To return to Windows, type
exit()at the Python prompt and press Enter.
Mistakes with the Two Prompts
Common mistake Assuming the Windows command prompt is already the Python shell.
What it looks likeThe terminal window is open, but the >>> prompt has not appeared.
Why it failsOpening the terminal only places you in the Windows command-line environment. Python has not started yet.
Do this insteadType python at the Windows command prompt and press Enter, then look for version information and >>>.
Common mistake Treating >>> as a Windows command prompt.
What it looks likeTrying to enter Windows commands after the >>> prompt appears.
Why it failsThe >>> prompt belongs to the Python interpreter and expects Python code.
Do this insteadUse Python code while >>> is visible. Type exit() and press Enter when you need to return to the Windows command line.
Common mistake Failing to verify startup.
What it looks likeAssuming Python is ready without checking the displayed prompt.
Why it failsThe visible version information and >>> prompt are the signs that the interpreter has started and is waiting for input.
Do this insteadCheck for both version information and the >>> prompt before entering Python commands.
Guided Terminal Check
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
- 1Open the Windows command line through Start, Run, cmd, and Enter.
- 2At the Windows command prompt, type python and press Enter.
- 3Verify startup by looking for Python version information and the >>> prompt.
- 4Remember that the Windows command prompt expects Windows commands, while >>> expects Python code.
- 5Use
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.