Nearby lessons

3 of 108

Python - 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:

  1. Python reads the statement.
  2. Python evaluates (executes) it.
  3. Python prints the result.
  4. 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

  1. Open the Start Menu.
  2. Search for Python IDLE.
  3. Open Python IDLE (Shell).

Method 2: Using Command Prompt

Open Command Prompt and type:

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Python 3.x.x
>>>

Alternative Command

You can also start Python Shell using:

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Python 3.x.x
>>>

Example 1 - Print a Message

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
Welcome to Python

Example 2 - Perform Addition

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
30

Example 3 - Compare Two Numbers

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
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 3 Runtime
Loading Editor...
Output Preview
Python Shell closes and you return to the Command Prompt.

Another Way to Exit

You can also use:

🐍
main.py
Python 3 Runtime
Loading Editor...
Output Preview
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 .py file for larger programs.
  • Use exit() or quit() 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()

🧠 Test Your Knowledge

8 Questions

Progress: 0 / 8
Keep Going!Python - Python IDLE