> Source URL: /resources/REPL.guide
# The Python REPL

The **REPL** is an interactive Python prompt where you can type one line of
code, press Enter, and see the result right away. No files, no saving — just
experiment.

`REPL` stands for **Read–Eval–Print–Loop**:

1. **Read** your input
2. **Eval**uate it
3. **Print** the result
4. **Loop** back for more

Think of it like a calculator for Python. It's the fastest way to test a
function, check what a variable looks like, or sanity-check an import.

---

## Starting the REPL

Open a terminal and type:

```bash
python
```

(or `python3` on some systems). You'll see something like:

```
Python 3.12.1 (main, ...)
Type "help", "copyright", "credits" or "license" for more information.
>>>
```

The `>>>` is the **prompt** — it means "Python is waiting for you to type
something."

To **exit** the REPL, type `exit()` and press Enter, or press `Ctrl+D`
(macOS/Linux) or `Ctrl+Z` then Enter (Windows).

---

## Your First REPL Session

Try typing each of these lines and pressing Enter after each:

```python
>>> 2 + 2
4
>>> name = "Ari"
>>> name
'Ari'
>>> print("Hello,", name)
Hello, Ari
>>> len("hello")
5
```

Notice:

- You don't need `print()` to see a value — just type the expression and Python
  will show its result.
- Variables you set (`name = "Ari"`) stay around for the rest of the session.
- Strings display with quotes (`'Ari'`) when printed automatically, but without
  quotes when you use `print()`.

---

## Importing Your Own Code

This is the most useful thing for project work. If you have a file
`recommend.py` with a function `recommend_clps`, you can test it without
running the whole app:

```python
>>> from recommend import recommend_clps
>>> from scraper import get_clp_events
>>> events = get_clp_events()
>>> recommend_clps(events, ["music"])
```

**Important:** start the REPL from the **same folder** as your `.py` files
(use `cd` to get there first). Otherwise Python won't find them.

```bash
cd path/to/your/project
python
```

---

## Multi-line Code

If you type something that needs more lines (like a function or an `if`
statement), the prompt changes to `...` to show Python is waiting for the
rest:

```python
>>> def greet(name):
...     return "Hello, " + name
...
>>> greet("Ari")
'Hello, Ari'
```

Press Enter on an empty `...` line to finish the block.

---

## Handy REPL Tricks

**Use the up arrow** to recall previous commands — great for re-running a test
after editing code.

**Check what type something is:**

```python
>>> type(events)
<class 'list'>
>>> type(events[0])
<class 'dict'>
```

**Peek inside a list or dict:**

```python
>>> events[0]
{'title': 'Music Night', 'interests': ['music', 'community']}
>>> events[0].keys()
dict_keys(['title', 'interests'])
```

**Get help on anything:**

```python
>>> help(str.upper)
>>> help(recommend_clps)
```

(Press `q` to exit the help screen.)

---

## If You Change Your Code

The REPL loads your module **once**. If you edit `recommend.py` while the REPL
is running, the old version is still in memory. The simplest fix: exit the
REPL (`exit()`) and start a fresh one.

---

## When to Use a REPL vs. a Test File

- **REPL:** quick, one-off checks. "Does this function return what I expect?"
- **Test file** (e.g. `test_recommend.py`): checks you want to re-run later, or
  a sequence of calls that's annoying to retype.

A test file is just a normal Python script — run it with `python test_recommend.py`.

---

## VS Code Shortcut

In VS Code you can open an integrated Python REPL with:

- Open a `.py` file
- Press **Shift+Enter** on a line → it sends that line to a Python terminal
- Or run the **Python: Start REPL** command from the command palette
  (`Cmd+Shift+P` / `Ctrl+Shift+P`)

---

_Tip: the REPL is your friend. Any time you're not sure what a piece of code
does, paste it in and see._


---

## Backlinks

The following sources link to this document:

- [Python REPL Guide](/resources/resources.index.llm.md)
- [REPL Guide](/unit-3/project-paths/makayla-c/makayla-c-2026-04-21.guide.llm.md)
- [REPL](/unit-3/project-paths/makayla-c/makayla-c-2026-04-18.guide.llm.md)
