Nearby lessons
3 of 108Python - Python 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
Python repeats this process every time you enter a command.
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:
main.py
Python 3.x.x >>>
Alternative Command
You can also start Python Shell using:
main.py
Python 3.x.x >>>
Example 1 - Print a Message
main.py
Welcome to Python
Example 2 - Perform Addition
main.py
30
Example 3 - Compare Two Numbers
main.py
True
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:
main.py
Python Shell closes and you return to the Command Prompt.
Another Way to Exit
You can also use:
main.py
Python Shell closes.
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() |