This is the first post in the Python track. It gets you from nothing installed to a program you wrote and ran yourself, then tells you what to read next.
Install Python
macOS ships with a Python, but it is there for the operating system's own use and is usually old. Install your own rather than fighting it.
# macOS
brew install python@3.12
# Ubuntu / Debian
sudo apt install python3.12 python3.12-venv
# Windows: download the installer from python.org and tick "Add Python to PATH"
Then check what you got. The command is python3 on macOS and Linux, and
python on Windows.
python3 --version
# Python 3.12.4
If that prints a version, you are done installing. If it says the command was not found, the
installer did not put Python on your PATH — reinstall and tick the box.
Your first program
Put this in a file called hello.py:
print("Hello, Python") # Output: Hello, Python
And run it:
python3 hello.py
That is the whole cycle. There is no compile step and no build tool — you hand a text file to the
interpreter and it runs it, top to bottom. If you have come from Java, notice what is missing: no
class, no main method, no javac. A Python file is a list of things to do.
The REPL, and when to use it
Run python3 with no filename and you get a prompt that evaluates whatever you type.
This is the REPL — read, evaluate, print, loop.
>>> 2 + 2
4
>>> name = "Ada"
>>> len(name)
3
The REPL is for questions, not for programs. "What does sorted() do to a dict?" is a
REPL question — you get the answer in five seconds instead of guessing. Anything you want to keep
goes in a file. Press Ctrl-D to leave.
Throughout this track, a block starting with >>> is a REPL session and the
line under it is what Python printed back. A block without it is a file you run.
Which Python this track uses
Every post here is written against Python 3.12, and every code sample is executed under it before publishing. Where 3.14 changed something you would actually meet, the post says so in a callout rather than assuming you have it.
3.12 is the baseline because it is what you will meet in real projects, and because everything in this track works on anything newer. If you have 3.13 or 3.14 installed, nothing here will break.
The Python releases
Python has no LTS releases. If you have come from Java, this is the first thing to unlearn — there is no 3.12-equivalent of Java 21 that gets eight years of support. Every 3.x release gets roughly two years of bug fixes and three more of security fixes, then it is done. The practical advice is simply to stay within the last two or three releases.
What each one added, limited to things you will actually recognise as you work through this track:
| Version | Released | What it added |
|---|---|---|
| 3.9 | Oct 2020 | Dict merge with |, str.removeprefix() and
removesuffix(), builtin generics so you write list[int] instead
of typing.List[int] |
| 3.10 | Oct 2021 | Structural pattern matching (match / case), X | Y for
union types, and dramatically better syntax error messages |
| 3.11 | Oct 2022 | 10–60% faster than 3.10, exception groups, and tracebacks that underline the exact expression that failed rather than just the line |
| 3.12 | Oct 2023 | This track's baseline. f-strings that can nest and reuse quotes, the
type statement, sharper error suggestions |
| 3.13 | Oct 2024 | A genuinely good interactive REPL with colour and multiline editing; the free-threaded (no-GIL) build as an experiment |
| 3.14 | Oct 2025 | Template strings, annotations evaluated lazily so type hints stop costing import time, free-threading officially supported |
The error messages line is not filler. Upgrading from 3.9 to 3.11 or later changes how much time you lose to a typo, which matters more when you are learning than any language feature on that list.
Virtual environments and pip
pip installs packages. The trap is installing them globally: two projects that need
different versions of the same library will fight, and eventually one of them loses. A virtual
environment is a private folder of packages for one project.
python3 -m venv .venv # create it, once per project
source .venv/bin/activate # switch to it (Windows: .venv\Scripts\activate)
pip install requests # goes in .venv, not on your system
deactivate # switch back
Make one per project and activate it before you install anything. Add .venv/ to your
.gitignore. You will not need any packages for the next several posts — the standard
library covers everything until the testing post — but build the habit now.
When it does not work
Four things go wrong on day one, and all four have the same fix once you know it.
command not found: python3 — Python is installed but not on your
PATH. Reinstall and tick "Add Python to PATH", or use the full path once to confirm the
install is fine.
python runs Python 2 — on some older systems the bare
python is the ancient one. Always type python3 on macOS and Linux.
IndentationError — Python uses indentation to decide what is inside
what, so spacing is syntax rather than style. Mixing tabs and spaces in one file is the usual cause.
Set your editor to insert four spaces for the Tab key and the problem disappears permanently.
SyntaxError pointing at a line that looks fine — look at the line
above it. An unclosed bracket means Python only notices something is wrong when it reaches
the next statement:
numbers = [1, 2, 3
print("this line gets blamed")
The error names the print, but the missing ] is the real problem. From
3.11 onwards the message says '[' was never closed and points at the right line, which
is one concrete reason not to run an old Python.
What to read next
The posts are written to be read in order, and each assumes the ones before it.
- The language — Introduction, Data Types, String Methods, f-strings, Conditional Statements, Iteration
- Collections — Lists, Tuples, Dictionaries & Sets
- Functions — Functions, Lambdas, Generators, Decorators
- Objects — Class, OOP, Dataclasses & Type Hints
- Everyday Python — Exceptions, Files, User Input, Modules & Packages, Async
- Working like a professional — Testing, Debugging, Best Practices, Code Snippets
Start with the Introduction, which explains what Python actually is and why indentation is part of the syntax.