Python
REPL
Learn to use Python's interactive interpreter to type expressions, read output instantly, and build intuition for how Python evaluates code.
What is a REPL?
REPL stands for Read-Eval-Print Loop. It is an interactive environment where Python reads what you type, evaluates the expression, prints the result, and then loops back to wait for more input.
The REPL Cycle in Action
Why Use the REPL?
The REPL is your fastest feedback loop. Instead of writing a whole program, saving a file, and running it, you get answers instantly. This makes it perfect for:
Expressions vs. Statements
Understanding the difference between these two is key to understanding what the REPL shows you.
The >>> Prompt
>>> 2 + 2
4
>>> for i in range(3):
... print(i)
...
0
1
2
How the REPL Evaluates
Python Types in the REPL
Every value in Python has a type. The REPL reveals types through the built-in type() function and through how values are displayed.
<class 'int'>
>>> type(3.14)
<class 'float'>
>>> type("hello")
<class 'str'>
>>> type(True)
<class 'bool'>
print() vs. Auto-Display
'hello' # auto-display: shows repr with quotes
>>> print("hello")
hello # print(): shows str without quotes
| Auto-Display (repr) | print() (str) | |
|---|---|---|
| Trigger | Type an expression alone | Call print() explicitly |
| String output | 'hello' (with quotes) | hello (no quotes) |
| None value | Shows nothing | Shows nothing |
| Multiple values | Only last expression | Each print() call |
Using the REPL: Step by Step
Example 1: Arithmetic
13
>>> 10 / 3
3.3333333333333335
>>> 10 // 3
3
>>> 10 % 3
1
>>> 2 ** 10
1024
Example 2: Strings & Booleans
'hello world'
>>> "ha" * 3
'hahaha'
>>> len("Python")
6
>>> 5 > 3
True
>>> 5 == 3
False
>>> "a" in "cat"
True
Example 3: Variables & Chaining
>>> y = 3
>>> x + y
10
>>> x ** y
343
>>> result = x * y + 1
>>> result
22
>>> type(result)
<class 'int'>
Common Mistakes in the REPL
Reading Error Messages
TypeError: can only concatenate str (not "int") to str
>>> 10 / 0
ZeroDivisionError: division by zero
>>> prnt("hi")
NameError: name 'prnt' is not defined
REPL Quick Reference
| You Type | REPL Shows | Why |
|---|---|---|
| 2 + 3 | 5 | Expression: auto-displayed |
| x = 5 | (nothing) | Statement: no return value |
| "hi" | 'hi' | repr() with quotes |
| print("hi") | hi | str() without quotes |
| 1 / 0 | ZeroDivisionError | Error: returns to prompt |
| type(42) | <class 'int'> | Expression: shows the type |
Question 1 of 5
What does REPL stand for?
Question 2 of 5
You type x = 10 in the REPL and press Enter. What appears on the next line?
Question 3 of 5
What is the output of 7 // 2 in the Python REPL?
Question 4 of 5
In the REPL, you type "hello" and press Enter. Then you type print("hello") and press Enter. How do the two outputs differ?
Question 5 of 5
What does the REPL display when you type 3 + 2 * 4?