The REPL (read-eval-print loop) is Python’s interactive prompt. You type one line of code, Python runs it, prints the result, and waits for the next line. It’s the fastest way to try ideas, check syntax, or do quick maths.

Start the REPL

Open a terminal and run:

uv run python

You’ll see something like:

Python 3.13.0 (main, Oct  7 2024, 12:00:00) [Clang 18.0] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> is the prompt. Python is waiting for you to type something.

Try a few lines

Type these and press Enter after each:

>>> 2 + 2
4
>>> 100 * 5
500
>>> "Hello" + " " + "Python"
'Hello Python'
>>> len("machine learning")
16

Each line you type is evaluated (run) and the result is printed below it. That’s the REP in REPL — read, eval, print, loop back for the next line.

Variables stick around

Variables you create in the REPL stay alive until you quit:

>>> name = "Manikandan"
>>> age = 30
>>> print(name, age)
Manikandan 30

Multi-line code

If you start a block of code, the prompt changes to ... to show Python is still reading:

>>> def greet(name):
...     return f"Hello, {name}"
...
>>> greet("World")
'Hello, World'

Press Enter on an empty line to finish the block.

Exit the REPL

When you’re done:

>>> exit()

Or press Ctrl+D (macOS/Linux) or Ctrl+Z then Enter (Windows).

When to use the REPL

The REPL is great for:

  • Checking syntax — “does this expression do what I think?”
  • Quick maths — it’s a calculator that knows Python
  • Exploring libraries — call a function, see what it returns
  • Reading documentationhelp(print) prints the docs for any function

It’s not great for:

  • Writing real programs — code disappears when you quit
  • Long scripts — typing more than a few lines gets clunky
  • Anything you want to keep — save your work in a file instead

A nicer REPL

Python’s built-in REPL is fine, but two upgrades are worth knowing:

  • IPython — a much friendlier REPL with colours, autocompletion, and better error messages. Install it with uv pip install ipython (later in this section).
  • Jupyter Notebook — a browser-based REPL where you can mix code, text, and charts. The standard tool in data science and ML.

We’ll use the plain REPL for now and stay focused on the language itself.

What’s next

The REPL is great for one-liners. Real programs live in files. Next we’ll write our first Python file and run it.

Toggle theme (T)