Nearby lessons
3 of 159Python - Python Shell
- Understand what the Python Shell is and when to use it
- Learn the REPL concept (Read, Evaluate, Print, Loop)
- Start and exit the Python Shell
- Try simple Python commands in the Shell
What is Python Shell?
Python Shell is an interactive environment where you can write and execute Python code immediately.
It is one of the easiest ways to learn Python because you can see the result as soon as you run a command.
Python Shell is useful for beginners to practise Python syntax and test small programs.
Uses of Python Shell
Python Shell is useful for:
- Learning Python.
- Testing small programs.
- Trying simple examples.
- Practising Python syntax.
- Performing quick calculations.
What is REPL?
Python Shell works using the REPL model.
REPL stands for:
- R - Read
- E - Evaluate
- P - Print
- L - Loop
How REPL Works
Whenever you enter a Python statement, the following steps are performed:
- Python reads the statement.
- Python evaluates (executes) it.
- Python prints the result.
- Python waits for the next statement.
This process continues until you exit the Python Shell.
How to Start Python Shell
You can start Python Shell in two ways.
Method 1: Using Start Menu
- Open the Start Menu.
- Search for Python IDLE.
- Open Python IDLE (Shell).
Method 2: Using Command Prompt
Open Command Prompt and type the following command. This is typed in the OS shell (Command Prompt), not inside Python:
pythonAlternative Command
You can also start Python Shell using this command. It is also typed in the OS shell (Command Prompt), not inside Python:
pyExample 1 - Print a Message
Example 2 - Perform Addition
Example 3 - Compare Two Numbers
When Should We Use Python Shell?
Python Shell is best for:
- Testing one or two lines of code.
- Checking Python syntax.
- Performing quick calculations.
- Learning Python step by step.
- Verifying small code examples.
Limitations of Python Shell
Python Shell is not suitable for:
- Large programs.
- Projects.
- Programs with many lines of code.
For complete programs, write the code in a .py file.
How to Exit Python Shell
To close the Python Shell, type:
exit()Typed in the Python shell, exit() closes the shell.
Another Way to Exit
You can also use:
quit()Typed in the Python shell, quit() closes the shell too.
Key Points
- Python Shell is an interactive environment.
- It works using the REPL model.
- REPL stands for Read, Evaluate, Print, and Loop.
- Python Shell is useful for learning and testing small programs.
- Use a
.pyfile for larger programs. - Use
exit()orquit()to close the Python Shell.
Quick Summary
| Topic | Description |
|---|---|
| Python Shell | Interactive environment to run Python commands. |
| REPL | Read, Evaluate, Print, Loop. |
| Python Prompt | >>> |
| Best For | Learning, testing, and small programs. |
| Exit Commands | exit() or quit() |
- Python Shell is an interactive environment for running Python commands
- REPL stands for Read, Evaluate, Print, and Loop
- Use python or py to start the Shell from Command Prompt
- Python Shell is great for learning and testing small programs
- Use exit() or quit() to close the Shell
- For larger programs, save code in a .py file instead