0.3First program & the interactive interpreter
The essentials in 30 seconds
- print displays: the basic tool to see what code does — one line is enough for a first program.
- REPL to try, file to keep: the REPL tests in 5 seconds without saving, the .py keeps a real program.
- Read the error from the bottom: the last line states the error, the lines above state where.
Running mini-case — Nabil writes his first report in Algiers
Nabil, a junior data analyst in Algiers, has his workstation ready: he wants to display his first sales report. He creates hello.py in VS Code with one print line, runs it and sees his message. He adds a comment and an f-string with his day total, observes top-to-bottom execution, then opens the REPL to test a calculation in 5 seconds without touching his file. His first error (a name without quotes) teaches him to read the traceback from the bottom: he fixes it and reruns.
Self-contained case for this section: it returns in the lesson, diagram, script and 48h challenge of section 0.3.
1. The REPL: the instant sandbox
Type python in the terminal: the >>> prompt runs each line at once (Read-Eval-Print Loop). Ideal for testing an idea in 5 seconds: a calculation, an f-string, a function. Quit with exit() — nothing is saved, that is the point. Nabil checks his sales total there before writing it in his report: explore first, build afterwards.
2. The .py file: the program that stays
In VS Code, create hello.py with print("Hello, Python!"), run it (run button or python hello.py in the terminal). The file persists, rereads, shares: anything beyond a trial lives in a file, never in the REPL. Code runs top to bottom, and # starts a comment ignored by Python to explain to humans. Nabil adds a second print line and a comment: his first report fits in three lines.
3. Reading an error without fear
A traceback reads from the bottom: the last line states the error (NameError when you forget quotes around text), the lines above state where. Pasting the error as is into a search engine solves most beginner blocks. In Python 3, accents display normally if files are saved in UTF-8 (VS Code does so by default). Nabil keeps the golden rule: an understood error is a free lesson — read, fix, rerun.
🔎 Concrete example — 🔎 Concrete example — First program, first error, first fix
Nabil's minimal report, with his first error lesson.
# hello.py — Nabil's first report
prenom = "Nabil"
total_ventes = 12
print(f"Hello {prenom}!")
print(f"Day total: {total_ventes} sales")
# Classic mistake: print(Hello) without quotes -> NameError
# Fix: print("Hello") with quotes -> text
Reading: Nabil runs hello.py: two lines displayed top to bottom; without quotes, Python looks for a variable and raises NameError.
Lesson: an understood error is a free lesson — read from the bottom, fix, rerun.
Section vocabulary
- print()
- Function displaying text or values on screen. The basic tool to see what a program does.
Simple example: Nabil displays his sales total with print in Algiers.
What it is not: a function saving to a file.
Reflex: display first to check, assume afterwards.
- REPL (interactive interpreter)
- "Read-Eval-Print Loop": you type a statement, Python runs it and displays the result at once. Launch it by typing python in the terminal.
Simple example: Nabil tests a calculation in 5 seconds without touching his file.
What it is not: an editor keeping programs.
Reflex: explore a small idea in the REPL before coding it.
- File .py
- A text file containing Python code, run as a block with python myfile.py.
Simple example: Nabil keeps his report in hello.py, rerunnable and shareable.
What it is not: a throwaway session vanishing on close.
Reflex: as soon as it goes beyond a trial, write it in a file.
- Comment
- Text ignored by Python, starting with #. Used to explain code to humans.
Simple example: Nabil notes why his total is computed that way.
What it is not: a statement run by Python.
Reflex: comment the "why", not each obvious line.
- Syntax
- The writing rules of the language. In Python, indentation (spaces at line start) is part of the syntax.
Simple example: Nabil minds his spaces: they structure his future blocks.
What it is not: a mere layout preference.
Reflex: mind the writing from the very first line.
In practice — In practice — Your first "Hello" — file and REPL
- In VS Code, create "hello.py", write: print("Hello, Python!") then run (run button or "python hello.py" in the terminal).
- Add a comment line (# my first line) and a second print statement: observe top-to-bottom execution.
- In the terminal, launch the REPL by typing "python". Type 2 + 3, then "a" * 5, and observe the immediate results.
- Quit the REPL with exit() or your system's shortcut, then trigger and fix an error read from the bottom.
Script ready to say — telling about your first program (30 s)
"I created hello.py: two prints, one comment, run from VS Code — it displays top to bottom. To test an idea in 5 seconds, I open the REPL with python; and facing an error, I read the traceback from the bottom before fixing, like Nabil."
Say while showing the hello.py file and the REPL open in the terminal side by side.
Copy-paste template — first report
# hello.py — Nabil's template (junior data analyst in Algiers)
# Each line runs top to bottom
prenom = "Nabil"
total_ventes = 12
print(f"Hello {prenom}!")
print(f"Day total: {total_ventes} sales")
print(f"Tomorrow: {total_ventes + 1} targeted sales")
No variable
Start with a fixed print ("Hello, Python!"), then introduce prenom and an f-string — one step at a time.
Error hunter
Deliberately remove quotes, read the NameError from the bottom, then fix it — the first error will never surprise you again.
Pairing in Algiers
Nabil dictates, his colleague types: one reads hello.py aloud (print, comment), the other describes what the terminal displays.
Towards calculation
Working report: add a calculation in the f-string (total + 1) and first check it in 5 seconds in the REPL.
✓ Best practices
- Use the REPL to try, the file to keep.
- Read the traceback from the bottom.
- Search the error as is.
✗ Common pitfalls
- Coding a whole project in the REPL (nothing is saved).
- Panicking facing a traceback instead of reading it.
- Fixing at random without reading the error.
Key takeaways
- print() displays on screen: the tool to "see" what code does.
- The REPL (python command) runs each line instantly: ideal for testing.
- A .py file runs as a block with "python file.py" and runs top to bottom.
- # starts a comment ignored by Python; read the traceback from the bottom.
48h challenge — apply tomorrow
Create hello.py with Nabil's template, run it, change the total, then test the calculation first in the REPL.
- My hello.py runs and displays my message with an f-string.
- I use print, comment and REPL without help.
- I read a traceback from the bottom and fix without panicking.
Frequently asked questions
What is the difference between the REPL and a .py file?
The REPL is a throwaway sandbox for testing a line or two and seeing the result at once. A .py file keeps a real program, rerunnable and shareable. Use both: the REPL to explore, the file to build.
Why does my accent or special character display badly?
Python 3 handles Unicode natively, so it is rare. If it happens, it is often a terminal encoding issue: make sure your files are saved in UTF-8 (VS Code does so by default).
What is the interactive interpreter (REPL) for?