Part 01 / Topic 4 of 7
REPL vs script
There are two ways to run Python. Both need a terminal: a window where you type commands (Command Prompt / PowerShell on Windows, Terminal on macOS / Linux).
Terminal basics: the terminal always works "inside" one folder. Move to the folder that has your file before you run it.
| Command | What it does |
|---|---|
cd python-practice |
Go into the folder python-practice (cd = change directory) |
cd .. |
Go up one folder |
ls (macOS / Linux) · dir (Windows) |
List the files in this folder |
Don't want to type commands? In VS Code you can also press ▶️ Run Python File; it opens a terminal and runs the file for you.
python or python3? On Windows type python (or py). On macOS / Linux type python3. This course writes python; use the one that works on your computer.
- REPL (Read–Eval–Print Loop): type
python(orpython3) in a terminal. You type one line, Python runs it at once. Good for quick tests. - Script: save code in a
.pyfile and runpython hello.py. Good for real programs you want to keep.
Real-world example: Check 250 * 12 in the REPL quickly; write a full salary calculator in a script.
$ python
>>> 250 * 12
3000
>>> name = "Asha"
>>> name.upper()
'ASHA'
>>> exit()
# hello.py → run with: python hello.py
print("Hello, World!")
print("Welcome to Python Step by Step")
# Output:
# Hello, World!
# Welcome to Python Step by Step
| REPL | Script (.py file) |
|
|---|---|---|
| Start | python |
python hello.py |
| Shows values automatically | Yes (>>> 2+2 shows 4) |
No, you must use print() |
| Code is saved | No | Yes |
| Best for | Quick experiments | Real programs |
| Exit | exit() or Ctrl+D (Ctrl+Z Enter on Windows) |
Ends at the last line |
🔍 Going deeper: Python 3.13 has a new REPL with colours, multi-line editing and
exitwithout brackets.python -i hello.pyruns a script and then drops you into the REPL with its variables still loaded, which is handy for poking at results.
🧪 Quick quiz — answer from memory, then check.
- You want to test
250 * 12quickly — REPL or script? - In the REPL, do you need
print()to see the value of2 + 2? - How do you leave the REPL?
Show the answers
- REPL — one line, instant answer.
- No. The REPL shows values automatically; in a script you need
print(). exit()orCtrl+D(Windows:Ctrl+Zthen Enter).
Done here? The practice set for Part 1 — 6 exercises with solutions — is on the part page.