You've probably typed python into a terminal and landed in a strange little prompt that just sits there waiting for input. That's the Python REPL, and understanding how it works — alongside the python interpreter that powers it — is one of those foundational things that makes everything else about learning Python click faster.
What is the Python Interpreter?
Programming languages generally fall into two camps: compiled and interpreted. A compiled language (like C or Rust) gets translated entirely into machine code ahead of time, producing a standalone executable. Python doesn't work that way. It's an interpreted language, which means the python interpreter reads your code and executes it directly, translating it into instructions the computer can run as it goes.
This matters practically because it changes your feedback loop. There's no separate "compile" step waiting between you and running your code — you write it, and the interpreter runs it, right then.
Two ways the interpreter executes code
The interpreter can operate in two different modes:
Script mode — you run an entire file at once, typically something with a
.pyextension:
python my_script.py
Interactive mode — you launch the interpreter with no file argument, and it drops you into a prompt where you type code one line (or block) at a time, see the result immediately, and keep going.
Interactive mode is where the REPL lives, and it's what the rest of this article focuses on.
CPython, the standard implementation
When people say "the Python interpreter," they usually mean CPython — the reference implementation of Python, written in C, maintained by the Python core team, and what you get when you download Python from python.org. Other implementations exist (PyPy, for instance, optimized for speed through just-in-time compilation), but CPython is what almost everyone uses day to day, and it's the one this article assumes.
What is the REPL? (Read-Eval-Print Loop)
So, what is REPL in Python, exactly? REPL stands for Read-Eval-Print Loop, and the name describes exactly what it does, step by step:
Read — it reads the line (or block) of code you typed.
Eval — it evaluates that code.
Print — it prints the result to your screen.
Loop — it goes back to step one and waits for your next input.
That cycle repeats for as long as your session stays open.
Launching the REPL
Open a terminal and type:
python
# or, depending on your system
python3
You'll land on a prompt that looks like this:
>>>
That >>> is the primary prompt — it means the interpreter is ready for a fresh line of input. If you start typing something that isn't finished yet (like the first line of a function), you'll see a different prompt:
...
That's the secondary prompt, and it means the interpreter is still waiting for more input to complete the current block.
Why it's called an "interactive shell"
The Python REPL is often called the python interactive shell because it behaves like a conversation: your keyboard is the input, your screen is the output, and there's no file being saved anywhere in between. You type a line, get a response, type another line, get another response. It's the fastest way to test an idea in Python without the overhead of creating and running a file.
Using the REPL: Practical Examples
The most natural way to get comfortable with the REPL is to just start typing things into it.
Using it as a calculator
>>> 7 * 6
42
>>> 100 / 4
25.0
Variable assignment
>>> name = "Alex"
>>> greeting = f"Hello, {name}!"
>>> greeting
'Hello, Alex!'
Notice you don't need print() at the REPL — typing an expression by itself automatically displays its result. That's a REPL-specific behavior; it won't happen the same way in a script.
Handling multi-line blocks
Try typing a for loop:
>>> for i in range(3):
... print(i)
...
0
1
2
The ... secondary prompt keeps appearing until you press Enter on a blank line, signaling the block is finished and ready to run.
Useful python REPL commands and shortcuts
Command history — press the Up and Down arrow keys to cycle back through what you've typed, instead of retyping it.
The underscore operator (
_) — after any expression, the REPL stores its result in a special variable named_, so you can reuse it:
>>> 15 + 27
42
>>> _ * 2
84
The REPL's big limitation
Nothing you type in the REPL is saved anywhere. Close the session, and it's gone — there's no file left behind. That makes it perfect for testing an idea, checking how a function behaves, or trying out unfamiliar syntax, but it's the wrong tool for building anything you actually want to keep. For that, you need script mode.
REPL vs. Script Mode: When to Use Each
Script mode: for real programs
Script mode is what you use for anything meant to be run more than once, shared, or built into something bigger. A typical script includes the if __name__ == "__main__": pattern, which lets a file behave differently depending on whether it's being run directly or imported by another file:
def main():
print("Running as a script")
if __name__ == "__main__":
main()
This pattern is standard in real Python projects — it keeps code reusable while still giving you a clear entry point when running the file directly.
REPL: for exploration
Use the REPL when you want a fast answer to a small question: "What does this method return?" "Does this list comprehension work the way I think it does?" "What's the syntax for this again?" It's also genuinely useful for debugging — you can inspect variables and try fixes on the fly without editing and rerunning a whole file.
How they work together
In a normal workflow, these two modes aren't competitors — they're complementary. You might test a tricky piece of logic in the REPL first, confirm it behaves the way you expect, and then copy it into your script once you're confident it's right. Experienced developers move between the two constantly.
5. Beyond the Standard REPL: Alternatives Worth Knowing
IDLE
IDLE is a simple GUI-based shell that ships bundled with most Python installations. It wraps the same interactive interpreter in a basic window with some added conveniences, like syntax highlighting. It's a fine starting point, though most working developers move on to something more capable fairly quickly.
IPython vs standard REPL
IPython is a significantly more feature-rich interactive shell, especially popular in data science work. It adds rich tab-completion, "magic commands" (special commands prefixed with %, like %timeit for quick benchmarking), and better support for inspecting objects. If you're planning to work with libraries like pandas or NumPy, IPython (or the Jupyter notebooks built on top of it) is worth installing early.
The new python REPL 3.13 and later
If you're using Python 3.13 or newer, you're already getting a meaningfully upgraded standard REPL compared to older versions. The interpreter now supports genuine multi-line editing — you can arrow up to a previous function or loop and edit the whole block at once, rather than retyping it line by line. It also added colorized output, direct commands like exit and help without needing parentheses, and a dedicated history browser you can open with F2. Python 3.14 went a step further, adding real-time syntax highlighting and import autocompletion as you type. These changes closed a lot of the gap that used to make people reach for IPython just for basic quality-of-life features.
Running the REPL inside VS Code
If you set up VS Code for Python using the steps from the previous article in this series, you already have quick access to a REPL without leaving your editor — the integrated terminal lets you launch python directly, and it respects whichever interpreter and virtual environment you've selected for the project. That means you can test a snippet in the REPL and immediately confirm it's using the exact same environment your actual script will run in — no more guessing which Python installation is answering your questions.