> ## Documentation Index
> Fetch the complete documentation index at: https://fastapi2day.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Interactive Python REPL and the VS Code Interactive Shell

> Use the Python REPL and VS Code's interactive window to run code cell by cell from .py files, inspect variables, and iterate quickly on AI projects.

When you write a full Python script and run it, you have to wait for the entire file to execute before you see any output. For small programs that is fine. But when you are building AI applications, processing data, or exploring an API response, you want to see results immediately after each step — adjusting, inspecting, and iterating as you go. That is exactly what interactive Python gives you. It is the development style used throughout this course, and once you experience it you will rarely want to go back to running whole files at once.

## Two ways to run Python interactively

### The Python REPL

The REPL (Read–Eval–Print Loop) is the simplest interactive Python experience. Open a terminal and type:

```bash theme={null}
python
```

You enter a live Python session where every line you type is executed immediately:

```python theme={null}
>>> name = "Python Learner"
>>> print(f"Hello, {name}!")
Hello, Python Learner!
>>> 2 + 2
4
>>> exit()
```

The REPL is useful for quick calculations and one-off checks, but it has a limitation: your code exists only in memory. When you close it, everything is gone.

### VS Code Interactive Window (recommended)

VS Code's Interactive Window gives you the best of both worlds: you write organised code in a `.py` file, but you can run any selection of it instantly in an interactive panel — with full output, variable persistence, and even inline visualisations. This is the workflow used throughout this course.

<Note>
  The Interactive Window is powered by the Jupyter extension. Make sure you have it installed (covered in the Setup page) before continuing.
</Note>

## Set up the Interactive Window

<Steps>
  <Step title="Install ipykernel">
    With your virtual environment active, install the IPython kernel:

    ```bash theme={null}
    pip install ipykernel
    ```
  </Step>

  <Step title="Enable Shift + Enter execution">
    1. Open Settings with `Ctrl/Cmd + ,`
    2. Search for **execute selection**
    3. Find **Jupyter › Interactive Window › Text Editor: Execute Selection**
    4. Check the box to enable it
  </Step>
</Steps>

With this setting enabled, highlighting any code in a `.py` file and pressing `Shift + Enter` will run it in the Interactive Window panel.

## Your first interactive session

<Steps>
  <Step title="Create a new file">
    Create a file called `interactive_demo.py` in your project folder.
  </Step>

  <Step title="Write some code">
    ```python theme={null}
    # Assign a variable
    name = "Python Learner"
    print(f"Hello, {name}!")

    # Create a list
    numbers = [1, 2, 3, 4, 5]
    print(f"Numbers: {numbers}")

    # Calculate the total
    total = sum(numbers)
    print(f"Total: {total}")
    ```
  </Step>

  <Step title="Run it interactively">
    Click on the first line, then press `Shift + Enter`. An Interactive Window opens on the right side of the editor and shows the output for that line.

    Keep pressing `Shift + Enter` to run line by line, or highlight a block of code and press `Shift + Enter` to run it all at once.
  </Step>
</Steps>

## What makes the Interactive Window powerful

### Variables persist across executions

Once you assign a variable in the Interactive Window, it stays in memory for your entire session. You do not have to re-run earlier lines every time you want to use a variable further down the file.

```python theme={null}
# Run this first
message = "Hello"

# Run this later — message is still available
print(message + " World!")

# Modify it and run again
message = message.upper()
print(message)  # HELLO
```

### Run only what you need

You can highlight any subset of your code — a single expression, a few lines, or a complete function — and run just that selection. This means you can test a new idea on line 50 without re-executing lines 1 through 49.

### See rich output

The Interactive Window renders output more richly than a plain terminal. DataFrames display as formatted tables, matplotlib charts appear inline, and long outputs are scrollable.

## Interactive workflow for AI development

When you are working with AI and data, this workflow is particularly valuable:

```python theme={null}
import requests

# Step 1: Make an API call and inspect the raw response
response = requests.get("https://api.github.com")
print(response.status_code)

# Step 2: Examine the JSON payload
data = response.json()
print(data.keys())

# Step 3: Extract what you need
description = data.get("description")
print(description)
```

Run each block separately. If something looks wrong in step 2, fix it and re-run just that block — no need to restart from the beginning.

<Tip>
  Think of the Interactive Window as cooking and tasting as you go, rather than waiting until the entire meal is prepared before trying any of it. You catch problems early and adjust in real time.
</Tip>

## Quick reference

| Action                           | How to do it                                                     |
| -------------------------------- | ---------------------------------------------------------------- |
| Run current line                 | Place cursor on line, press `Shift + Enter`                      |
| Run selected code                | Highlight code, press `Shift + Enter`                            |
| Open Interactive Window manually | `Ctrl/Cmd + Shift + P` → **Jupyter: Create Interactive Window**  |
| Clear the Interactive Window     | Click the trash icon in the panel toolbar                        |
| View all variables in memory     | Click the **Variables** button in the Interactive Window toolbar |

<Card title="Start learning Python" icon="rocket" href="/basic-python/python-basics">
  Your environment is ready. Let's dive into Python fundamentals!
</Card>
