Three different ways to run the exact same Python code, and when you'd reach for each one.
By now you've probably run a line or two of Python in Google Colab. This topic zooms out and compares the three main ways people actually run Python code day to day: a notebook (Colab), a code editor (VS Code, running a local file), and a bare terminal (typing directly into the Python interpreter). Same language, three very different workflows โ knowing when to use which will save you a lot of friction later.
.py text file containing Python code, run from start to finish in one go.| Method | What it is | Best for |
|---|---|---|
| Colab (notebook) | Cells you run one at a time in the browser; output appears inline | Learning, experimenting, data work, quick sharing |
| Local script (VS Code) | A .py file you write and run as a whole | Real projects, anything you'll reuse or version-control |
| Terminal (REPL) | Typing Python directly into a command line, one statement at a time | Quick one-off checks, debugging, exploring a library |
Open a notebook at colab.research.google.com, click into a cell, and run it with Shift + Enter:
print("Hello from Colab!")
Hello from Colab!
The output appears directly under the cell. You can re-run individual cells in any order, which is great for experimenting โ but it also means the notebook's "state" can get confusing if you run cells out of sequence.
Create a file called hello.py:
print("Hello from a local script!")
Then run the whole file from a terminal:
python hello.py
Hello from a local script!
Unlike a notebook, a script always runs top to bottom, in order, every single time โ no hidden state left over from a previous run. This predictability is exactly why real projects are built as scripts, not notebooks.
Open a terminal and just type python (or python3 on Linux/macOS) with no filename:
$ python
Python 3.12.4 (main, ...)
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello from the REPL!")
Hello from the REPL!
>>> 2 + 2
4
Each line runs the instant you press Enter โ there's no file being saved anywhere. Type exit() or press Ctrl+D (Ctrl+Z then Enter on Windows) to leave.
๐ก Tip: The REPL is perfect for quickly checking "wait, what does this expression actually return?" without creating or editing any file.
len([1,2,3]) returns? โ The terminal/REPL โ fastest possible round trip.๐ก In practice, most working developers move fluidly between all three in the same day: REPL to check a quick idea, scripts for the actual project, notebooks for exploring data or sharing a walkthrough.
There are three common ways to run Python: a notebook like Colab (cell by cell, output inline โ great for learning and experimenting), a local script run with python filename.py (runs top to bottom every time โ the right choice for real projects), and the terminal/REPL (type python, run one line at a time, no file saved โ best for quick one-off checks). Same language, three different workflows for three different jobs.