How Python Works: Interpreter & Scripts
Computers only understand one language: machine code — billions of tiny on/off electrical signals represented as 1s and 0s. Everything else — Python, English, emoji — is for humans. So how does your Python code become electricity?
The translator metaphor
Imagine you speak only Hindi and need to give instructions to someone who speaks only Tamil. You have two options:
Languages like C use option 1 — a compiler translates the whole program into machine code *before* it runs. Python uses option 2 — the Python interpreter reads your code and executes it line-by-line, on the spot.
You write: print("hello")
↓
Interpreter: translates + runs that line, immediately
↓
Screen: helloWhat this means for you (the good)
python, then 2 + 2 and press Enter.What this means for you (the tradeoff)
Interpreting line-by-line is slower than running pre-translated machine code. That's the "Python is slow" thing from the last lesson. For the apps in this course — and for most real-world software — the difference is invisible.
Scripts: the files you'll live in
A script is just a text file full of Python instructions, saved with the ending .py:
my_first_script.pyThat's genuinely it. A Python "program" is not a special binary file or an installer — it's a text file you could open in Notepad. The interpreter reads it top to bottom, executing each line in order:
# the interpreter runs these IN THIS ORDER
print("first") ← 1st
print("second") ← 2nd
print("third") ← 3rdOrder matters. If line 1 uses a variable that line 5 creates, line 1 fails — the interpreter hasn't reached line 5 yet. This "top-to-bottom" thinking becomes very important later, especially in Streamlit where the whole script re-runs on every click.
The two ways you'll run Python
python in a terminal, experiment line-by-line, press Ctrl+D (or exit()) to leave. Great for quick tests..py file, run python my_file.py. This is how every project in this course works.One more thing: Python is everywhere you'll look
When you install Python, you get the interpreter plus the standard library — hundreds of built-in toolboxes (math, files, dates, random numbers...) that need no installation. That's why Python "batteries are included."
✅ Checkpoint
.py file, really? *(A plain text file of Python instructions)*Next: we install Python and VS Code, and all of this becomes real on your machine.