Getting Python Running: Interpreter, Scripts, Jupyter & Colab
What Python is, the three ways to run code, how to verify your install, and how notebook state differs from a script.
- Verify a Python 3 installation and start and exit the interactive interpreter
- Write, save and run a .py script from the terminal
- Run multi-cell code in Google Colab or Jupyter and explain how kernel state works
- Choose the right runner (interpreter, script or notebook) for a given task
Day one of every Python class splits into two groups: the students who spend the evening fighting an installer, and the one who opens colab.research.google.com and runs their first line in forty seconds. Nothing in this course is learned by reading alone — you learn Python by running Python. Ten minutes to a working runner removes the only real barrier between you and every lesson after this one.
What Python actually is. Python is a high-level programming language. When you run a .py file, Python first translates your source into an intermediate form called bytecode, and then a Python runtime executes that bytecode. You never see or manage that translation — there is no separate "compile" step to remember. Edit, run, read the result, edit again. That fast iteration loop is a large part of why Python won data science and AI: when your work is exploration, the speed of the edit-run cycle often matters more than the raw speed of the executed code.
Three ways to run code — and they behave differently:
- The interpreter (REPL). Type
python3at a terminal (often justpythonon Windows) and you get a>>>prompt. Every line you type is evaluated immediately and its result printed.exit()returns you to the shell. Perfect for checking what one line does — terrible for anything longer than a screen, because the session ends when you close it. - A script. A plain text file ending in
.pyholding a sequence of statements. You run it withpython3 myfile.py, it executes top to bottom exactly once, prints whatever you print, and exits. State does not survive: every run starts fresh. This is how real programs are delivered. - A notebook (Jupyter or Google Colab). Code is split into cells you run one at a time, in any order you like, in a kernel — a long-lived process that keeps every variable alive between cells. Cell 1 can load a dataset; cells 2–50 can explore it without reloading. Notebooks are the native format of AI work: almost every ML tutorial, Kaggle analysis and research result you meet is a notebook. Their power (experiment interactively) is also their trap (state can go stale — see below).
Which one when. Interpreter: a one-line question ("does this sort work?"). Script: anything you will keep, re-run, or hand to someone else. Notebook: data analysis, charts, teaching, and learning — which is why this course shows notebook cells alongside runnable scripts.
Installing, honestly. Only Python 3 matters — Python 2 reached end of life in 2020 and any python2 you find is a museum piece. Current versions are 3.11 through 3.13; any of them runs every example in this course. On Windows, install from python.org and tick "Add python.exe to PATH" during setup — skipping that box is the single most common reason the python command mysteriously does not exist later. macOS and most Linux distributions already ship python3. Google Colab needs no installation at all: a free Linux machine in your browser with NumPy, pandas, matplotlib and much of the AI stack preloaded. The catch is ownership: a Colab machine is rented RAM tied to your session, so anything you want to keep must be saved to Google Drive or downloaded before you disconnect.
| Runner | Best for | State between runs | How you start it |
|---|---|---|---|
| Interpreter | Testing one line | Dies when you exit | python3 at the terminal |
| Script (.py) | Anything you keep or ship | None — fresh every run | python3 myfile.py |
| Notebook (Jupyter/Colab) | Analysis, AI work, teaching | All variables live in the kernel | Browser tab or jupyter notebook |
If anything about installing fails, open incognito chrome and go to colab.research.google.com → File → New notebook. You get a working Python 3 session with the AI stack in under a minute. Come back to local installs after Lesson 3.
On macOS and Linux the bare command python is either missing or points at Python 2, which will reject modern syntax with confusing errors. Get in the habit of typing python3 (and verifying python3 --version). On Windows the installed command is python.
- 1
1. Check what is installed
In a terminal, ask Python for its version. Any 3.x answer means you are ready; a "command not found" means install first (or just use Colab).
python3 --version # Windows: python --version # Expected: Python 3.12.7 - 2
2. Talk to the interpreter
Start the interpreter, evaluate two lines, then leave. The >>> prompt means Python is waiting for one statement at a time.
python3 >>> print(3 * 14) 42 >>> exit() - 3
3. Run a saved script
Put this in a file named hello.py in a folder you know, then run it by path. Output is plain — no prompts, no In/Out numbers.
# hello.py name = "Ada" print("Hello,", name) # then in the terminal: python3 hello.py - 4
4. Run a notebook cell
Open colab.research.google.com → New notebook. Paste into the first cell and press the play button (or Shift+Enter). A second cell can print(x) — the kernel kept x alive. Close the tab and both are gone.
x = 6 * 7 print(x) # 42
Solution
Version check gives Python 3.x; the interpreter answered 42 for one line; hello.py printed "Hello, Ada" as a one-shot script; the notebook kept x across cells. Recognise each output style — prompt-led (interpreter), plain (script), numbered cells (notebook) — because confusing them is how people misread where a result came from.
Open Colab (or your local install) and run three cells in order: (1) print your Python version with import sys; print(sys.version), (2) create a variable student = "your name" and print it, (3) print the variable again after re-running cell 1. Note exactly what persists and what does not.
Hint: Re-running cell 1 does not touch student, because cells share one kernel — but restarting the runtime (Runtime → Restart runtime) wipes everything.
Typing python and getting "command not found" or an ancient Python 2 banner
Use python3 explicitly and confirm with python3 --version. On Windows, reinstall from python.org with the "Add to PATH" checkbox ticked.
Expecting notebook variables to survive closing the browser
The kernel is rented memory tied to your session. Save code cells (they are safe in the file); re-run them after a restart to rebuild state.
Running python myfile.py from a folder that does not contain the file
The error "can't open file ... myfile.py" is a path problem, not a Python problem. cd to the folder first, or pass the real path: python3 scripts/hello.py.
Assuming everything you run shares one environment
Your terminal, your local Jupyter kernel and a Colab session are three separate Pythons with separate packages. This is exactly why Module 3 covers virtual environments.
What is the difference between a compiled and an interpreted language, and where does Python actually sit?
A compiled language (C, C++, Rust) translates the whole source into machine code ahead of time, producing a separate executable you then run. An interpreted language executes the source (or an intermediate form of it) statement by statement at run time. Python is a hybrid: it compiles source to bytecode — cached in a __pycache__ folder — and executes that bytecode on a virtual machine, so there is no separate build step but also no direct machine-code translation. The trade-off is rapid edit-run iteration and portability across platforms versus lower raw execution speed, which is precisely the gap libraries like NumPy close later in this course.
Source: Standard opening question in Python placement rounds and university unit tests.
- Python runs three ways: interpreter (one line at a time), script (top to bottom once), notebook (cells with live kernel state).
- Running Python compiles to bytecode behind the scenes — no separate compile step, fast edit-run loop.
- Only Python 3 matters; verify with python3 --version and beware the python versus python3 naming trap.
- Colab gives you a free, preloaded environment in the browser — but its state and files are session-bound.
- Notebook state lives in the kernel: persistent until you restart, unreliable if you run cells out of order.