Getting StartedBeginner7 min05 / 63

The Interactive Shell (REPL)

Learn how to use Python's interactive shell to experiment with code instantly, one line at a time.

Imagine you could ask Python a question and get an answer immediately — without writing a whole program first. That's exactly what the REPL lets you do.

The word REPL stands for Read-Eval-Print Loop. It reads what you type, evaluates (runs) it, prints the result, then waits for your next input. It loops forever until you decide to leave. Think of it as a live conversation with Python.

See it in action

Visual walkthrough1 / 6
1

Python Talks Back Instantly

The REPL is a live conversation with Python — type something, press Enter, and Python replies right away. No files, no waiting.

REPL stands for Read-Eval-Print Loop: it reads your input, runs it, prints the result, and loops.

#Starting the REPL

To open the REPL, open your terminal (also called the command line or shell) and type python — with no filename after it — then press Enter.

You'll see something like this:

The >>> prompt means Python is ready and waiting for you.
$ python
Python 3.12.0 (main, ...)
Type "help", "copyright", "credits" or "license" for more information.
>>>
Note

python vs python3

On some computers you need to type python3 instead of python to get Python 3. If python opens Python 2 (you'll see "Python 2.x" in the greeting), use python3 instead.

#Typing Your First Expressions

Once you see >>>, Python is listening. Type any expression and press Enter — Python will evaluate it and print the result right away. No print() needed!

Python evaluates each expression and shows the answer instantly.
>>> 2 + 2
4
>>> 10 * 3
30
>>> 100 / 4
25.0
It works with text too. len() counts the characters in a string.
>>> "Hello" + " " + "world"
'Hello world'
>>> len("Python")
6
Think of it like

Think of it like a calculator

A pocket calculator shows you the result the moment you press =. The REPL works the same way — type an expression, press Enter, see the answer. The difference is that Python can do much more than arithmetic.

#Variables Work Too

You can create variables in the REPL just like in a regular Python file. They stick around for as long as the REPL session is open.

Variables you define in one line are available in the next.
>>> name = "Ada"
>>> age = 36
>>> print(f"Hello, {name}! You are {age} years old.")
Hello, Ada! You are 36 years old.
Common mistake

Variables disappear when you exit

Everything you type in the REPL is temporary. The moment you close the REPL session, all your variables vanish. If you want to keep your work, save it to a .py file instead.

#Exploring with help() and dir()

The REPL comes with two handy built-in tools for learning on the fly.

  • help(something) — shows you the official documentation for that thing.
  • dir(something) — lists all the methods and attributes available on that thing.
dir() reveals all the things you can do with a string. It's like peeking inside a toolbox.
>>> dir("hello")
['capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', ...]
help() gives you a plain-English explanation of any function or method.
>>> help(str.upper)
Help on method_descriptor:

upper(...)
    S.upper() -> str

    Return a copy of S converted to uppercase.
Tip

Use dir() when you forget a method name

Forgot whether it's .append() or .add() for lists? Just type dir([]) in the REPL and scan the output. No need to Google it.

#REPL vs. a .py File

The REPL is great for quick experiments, but for real programs you write code in a file ending with .py and run it with python my_script.py.

Here's a simple comparison:

  • REPL — instant feedback, great for trying things out, nothing is saved.
  • .py file — your code is saved, you can run it again and again, perfect for real programs.
Running a .py file: $ python greet.py
# This is saved in a file called greet.py
name = "Ada"
print(f"Hello, {name}!")

#Leaving the REPL

When you're done, you can exit the REPL in two ways:

  • Type exit() and press Enter.
  • Press Ctrl + D (on Mac/Linux) or Ctrl + Z then Enter (on Windows).
Typing exit() ends the session and returns you to the regular terminal.
>>> exit()
Quick check

Which of the following is the correct way to open the Python REPL in your terminal?

Key takeaways

  • The REPL starts when you type `python` in your terminal with no filename — look for the `>>>` prompt.
  • You can type any expression and Python evaluates it instantly — perfect for experimenting.
  • Variables created in the REPL are temporary; they disappear when you close the session.
  • `dir()` lists what you can do with any object; `help()` explains how to do it.
  • Use the REPL for quick experiments, and `.py` files for programs you want to keep.
Practice challenges
Test yourself · earn XP
0/4
Predict the output#1

You type the following into the Python REPL. What does Python show?

predict-output
>>> 10 * 3
>>> 100 / 4
Fix the bug#2

A beginner wants to open the Python REPL but nothing interactive appears — Python just runs and exits. What is wrong?

fix-bug
$ python greet.py
Fill in the blank#3

Complete the REPL session so it greets Ada by name using an f-string.

>>> name = "Ada"
>>> print(f"Hello, !")
Reorder the lines#4

Put these REPL lines in the right order to define a variable, calculate with it, and then exit.

1
>>> x * 10
2
>>> x = 5
3
50
4
>>> exit()
Your turn
Practice exercise

Open the Python REPL and do the following: 1. Calculate (15 + 7) * 3 and note the result. 2. Store your first name in a variable called name. 3. Use print() to greet yourself: "Hello, [your name]!" 4. Run dir("") and find at least one string method you haven't used before. 5. Exit the REPL using exit().

Try it live — edit the code and hit Run to execute real Python:

solution.py · editable