Running Your First Script โ€” Colab vs Local vs Terminal

Three different ways to run the exact same Python code, and when you'd reach for each one.

Overview

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.

๐Ÿ“Œ This topic is optional. You already know enough to keep going with Colab. Read this whenever you're curious how "running Python" looks outside the browser.

Key Concepts

The Three Ways, Side by Side

MethodWhat it isBest for
Colab (notebook)Cells you run one at a time in the browser; output appears inlineLearning, experimenting, data work, quick sharing
Local script (VS Code)A .py file you write and run as a wholeReal projects, anything you'll reuse or version-control
Terminal (REPL)Typing Python directly into a command line, one statement at a timeQuick one-off checks, debugging, exploring a library

1. Running in Google Colab

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.

2. Running a Local Script (VS Code)

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.

3. Running Directly in the Terminal (REPL)

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.

How to Choose

๐Ÿ’ก 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.

Things to Remember

Quick Revision

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.