Nearby lessons

3 of 159

Python - Python Shell

📌 What You Will Learn
  • 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
Key Point: REPL means Python reads your command, runs it, shows the result, and then waits for your next command. This loop continues until you exit.

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 the following command. This is typed in the OS shell (Command Prompt), not inside Python:

python

Alternative Command

You can also start Python Shell using this command. It is also typed in the OS shell (Command Prompt), not inside Python:

py

Example 1 - Print a Message

🐍Code Cell
1print("Welcome to Python")
Output
Welcome to Python

Example 2 - Perform Addition

🐍Code Cell
110 + 20
Output
30

Example 3 - Compare Two Numbers

🐍Code Cell
110 < 20
Output
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:

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 .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()
📝 Key Takeaways
  • 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

🧠 Test Your Knowledge

8 Questions
Progress: 0 / 8