01 / 21
>>>

Python
REPL

Learn to use Python's interactive interpreter to type expressions, read output instantly, and build intuition for how Python evaluates code.

Python

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.

Read
Python reads the expression you type at the prompt
Eval
It evaluates (computes) the expression's value
Print
It prints the result to the screen immediately
Loop
It returns to the prompt, ready for your next input

The REPL Cycle in Action

Read Eval Print Loop The cycle repeats every time you press Enter

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:

1
Exploring new ideas: Test a small expression before putting it in a larger program.
2
Debugging: Check what a variable holds or whether a function works as expected.
3
Learning: See immediately how Python handles types, operators, and syntax.
4
Quick calculations: Use Python as a powerful calculator with \( +, -, \cdot, /, ** \) and more.

Expressions vs. Statements

Understanding the difference between these two is key to understanding what the REPL shows you.

Expression
A piece of code that produces a value. The REPL automatically prints it. Examples: 3 + 4, len("hi"), True
Statement
A piece of code that performs an action but has no value. The REPL prints nothing. Examples: x = 5, import math

The >>> Prompt

>>> # This is the primary prompt
>>> 2 + 2
4
>>> for i in range(3):
...    print(i)
...
0
1
2
>>>
Primary prompt: Python is ready for a new expression or statement
...
Continuation prompt: Python expects more lines (inside a block or unfinished expression)

How the REPL Evaluates

You type: 3 ** 2 + 1 Python parses (3**2) + 1 Evaluates to 10 Operator Precedence (highest to lowest): ** Exponent * / // % Mult/Div + - Add/Sub < > == != Compare Decreasing precedence →

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.

>>> type(42)
<class 'int'>
>>> type(3.14)
<class 'float'>
>>> type("hello")
<class 'str'>
>>> type(True)
<class 'bool'>

print() vs. Auto-Display

>>> "hello"
'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

1
Open a terminal and type python3 (or python) to launch the REPL. You should see the >>> prompt.
2
Type an expression after the prompt, such as 2 + 3 or "hello".upper().
3
Press Enter. Python evaluates your input and prints the result on the next line.
4
Read the output. If it is a value, the REPL auto-displays it. If nothing appears, your input was a statement.
5
Iterate. Try variations, assign to variables, call functions. Type exit() or press Ctrl+D to quit.

Example 1: Arithmetic

>>> 10 + 3
13
>>> 10 / 3
3.3333333333333335
>>> 10 // 3
3
>>> 10 % 3
1
>>> 2 ** 10
1024

Example 2: Strings & Booleans

>>> "hello" + " world"
'hello world'
>>> "ha" * 3
'hahaha'
>>> len("Python")
6
>>> 5 > 3
True
>>> 5 == 3
False
>>> "a" in "cat"
True

Example 3: Variables & Chaining

>>> x = 7
>>> y = 3
>>> x + y
10
>>> x ** y
343
>>> result = x * y + 1
>>> result
22
>>> type(result)
<class 'int'>

Common Mistakes in the REPL

✕ Confusing = and ==
x = 5 assigns. x == 5 compares. Using = when you mean == causes silent assignment instead of a True/False check.
✕ Expecting print from statements
Typing x = 10 and wondering why nothing appeared. Statements don't produce REPL output: type x on the next line to see the value.
✕ Forgetting integer division
7 / 2 gives 3.5 (float), not 3. If you want an integer result, use 7 // 2. Mixing these up can cause type errors downstream.

Reading Error Messages

>>> "age: " + 25
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?