Python from Scratch to Intermediate
Learn to program in Python from the very first line, up to writing a small, tested package with classes, files and a command-line tool. No experience needed.
You build one thing: the records program for Booknook, the lending shelf in the corner of a café called Kettle and Page. Twenty-four donated books, six members, a two-week loan and a small late fee for the charity jar. You start by printing one book's details and finish with a command Amira, the owner, can run each morning to see what is out, who is late and what is owed. Booknook and its people are fictional and its loans are simulated; the books are real public-domain titles, and every lesson also opens with a real, cited case.
Who this course is for
Anyone who wants to write programs, starting from nothing. You need to be able to use a web browser and copy and paste. You do not need to know any maths beyond adding and multiplying.
| You are... | Start at |
|---|---|
| New to programming | Module 1, and go in order |
| Someone who has tried a little Python and got stuck | Module 1 quickly, then Module 2; slow down at Module 5 |
| Comfortable with variables, loops and lists | Module 6 (functions) |
| Able to write functions, never built a package | Module 7 |
| Confident with Python, weak on classes or testing | Module 9, then Module 10 |
Every module's README lists what you need to know before starting it, so you can check whether it is safe to skip the one before. After this course, Module 1 of the AI Engineering course is a quick review rather than new material.
What you need
- A Google account, to run code in Google Colab. Nothing to install, and nothing to pay.
- No API keys and no accounts with any other service. The course never calls a language model.
- Optionally, your own computer with Python 3.12, for the parts that happen in a terminal. One page shows how: course-guide/07-run-locally.md.
Setup takes about five minutes: course-guide/02-setup-colab.md.
The modules
| # | Module | What you add to the shelf | Needs first |
|---|---|---|---|
| 1 | Getting Started | One book and one loan held in variables, printed as Amira's first shelf card | Nothing |
| 2 | Values, Types and Operators | The late fee in whole pence, capped at £3.00, with input() for the days late | Module 1 |
| 3 | Strings and Text | Tom's notebook lines cleaned by hand; a lined-up loan slip with f-strings | Module 2 |
| 4 | Decisions and Loops | Twelve loans labelled on time, due soon or overdue, and the fees totalled | Module 3 |
| 5 | Collections | The full catalogue as a list of dictionaries; what is out, who has it, books per genre | Module 4 |
| 6 | Functions | due_date, days_late, is_overdue, late_fee and reminder_text, each checked with assert | Module 5 |
| 7 | Modules, the Standard Library and Packages | The booknook package (dates.py, fees.py, catalogue.py) with real dates | Module 6 |
| 8 | Errors, Files and Debugging | storage.py: the CSV and JSON files loaded, Tom's notebook parsed into a problem list, clean files saved | Module 7 |
| 9 | Classes and Objects | models.py: Book, Member and Loan dataclasses and a Library that lends, returns and reports | Module 8 |
| 10 | Intermediate Python | A loan-history generator, a logging decorator, a safe-save context manager and 15 or more pytest tests | Module 9 |
| 11 | Capstone | The Booknook command-line tool, python -m booknook report, overdue, lend and return, tested, with a README | Modules 1 to 10 |
What you have at the end
One repository, booknook/: a Python package with eight modules, the four data files, a tests/ folder of pytest tests and a README. It reads the shelf's records, reports every faulty line in Tom's notebook instead of guessing, refuses a fourth book to a member who has three, works out fees the same way every time, and saves its files safely. The full layout is in course-guide/03-the-booknook-project.md.
How each lesson works
Every lesson is a walk through one Booknook example, one picture at a time:
- The situation: something Amira needs from the shelf.
- A real case, first: something that really happened, or a page of Python's own documentation, from a published source, cited.
- The idea: fifteen to thirty figures, one idea each, one running example.
- Run it: short code with a walkthrough of every line.
- Break it: an error you cause on purpose, and how to read it.
- In production: how working programmers use the idea.
- Check yourself: questions, one exercise with a check, key terms and sources.
Each module ends with a lab (a guided piece of the shelf) and an incident file (a real, published failure caused by the kind of mistake the module teaches you to avoid, replayed at Booknook and fixed). Every output shown in the course comes from a real run. More detail: course-guide/01-how-this-course-works.md.
The tools you will use
Python 3.12, the version Colab runs, and its standard library: datetime, pathlib, csv, json, collections, math, random, contextlib and others that come with every Python. One extra package, pytest, for testing in Module 10. Everything is open source and free.
Where other courses go deeper
This course stops at intermediate Python. For what comes next:
- Async code, project tooling (uv, linters, pre-commit) and version control with Git: Module 1 of the AI Engineering course.
- Using Python to build applications on language models: the AI Engineering and Large Language Models courses.
Course guide
| File | Read it when |
|---|---|
| 01-how-this-course-works.md | Before your first lesson |
| 02-setup-colab.md | Before you run any code |
| 03-the-booknook-project.md | To meet the café, the people, the rules, the dates and the files you will build |
| 06-shared-data.md | To see the Booknook data every module reuses |
| 07-run-locally.md | When you want Python on your own computer (Module 1 Lesson 2 and Module 7 Lesson 4 point here) |
| 04-style-guide.md | Only if you are writing or editing lessons |
| 05-image-style-guide.md | Only if you are drawing the course figures |
The one idea
A program is a set of rules written so exactly that a computer can follow them, and tested so that you know it still does. The shelf has four rules: fourteen days, twenty pence a day, three pounds at most, three books each. By the end you can write them down that exactly.