Write It Once, Use It Everywhere
The moment your programs stop being one long script. Define your own commands, pass data in, send answers back, and learn why a name inside a function is invisible outside it. Six lessons, ending with a toolbox you keep using.
What you should already know
- Basics only: variables and types,
input()andprint(), arithmetic and comparison operators,if/elif/else,whileandforloops. - Nothing else in this level. Each section stands on its own — you may take them in any order, though Functions makes the other four easier to write.
- 01
Your First Function:
defand Calling ItGive a block of code a name, then use that name as often as you like.
- 02
Parameters: Passing Data In
One function, many jobs — send it different values each time you call it.
- 03
Return Values: Sending an Answer Back
The difference between a function that shows and one that gives — and why it matters.
- 04
Default and Keyword Arguments
Sensible defaults, arguments named at the call, and the order rules that trip everyone.
- 05
Scope: Where a Name Lives
Why the function cannot see your variable, and why that is a feature.
- 06
Project: Your Own Function Toolbox
Six functions, one menu, and a file you will reuse in every later project.
Everything You Can Do to a List
A list is the container you reach for first, so learn the whole toolkit properly: reading items, changing them, adding and removing them, searching, and sorting by whatever rule you choose. Ends with a full create-read-update-delete manager.
What you should already know
- Basics only: variables,
input(), operators,if/else, andforloops. - Helpful but not required: Section 1 · Functions — the project lesson is tidier when written as functions.
- 01
Access: Index, Negative Index, Slicing
Reach any item, count from the back, and take a run of items at once.
- 02
Change: Assign, Insert, Replace a Slice
Lists are mutable — edit in place instead of rebuilding.
- 03
Add & Remove: append, insert, pop, remove, del
Five ways to grow and shrink a list, and when each is the right one.
- 04
Search & Count:
in, index, count, lenAsk a list what it holds without looping by hand.
- 05
Sorting: sort vs sorted, reverse,
key=Order a list by anything you like — length, price, last letter.
- 06
Project: A CRUD List Manager
Add, view, edit and delete — the four operations behind every app.
Labelled Storage
When a position is not enough and you need a name for each value. Create pairs, look them up safely, change and remove them, loop over both halves at once, and nest dictionaries inside lists to model something real.
What you should already know
- Basics only: variables,
input(),if/else, andforloops. - Helpful but not required: Section 2 · Lists — the last two lessons put dictionaries inside lists.
- 01
Key–Value Pairs:
[]vsget()Build your first dictionary, and look things up without crashing.
- 02
Change & Add: assignment, update, setdefault
One syntax adds and edits — which is either handy or a trap.
- 03
Remove: pop, popitem, del, clear
Take pairs out safely, and get the value back as you go.
- 04
Loop It: keys, values, items,
inWalk a dictionary properly, and test membership before you read.
- 05
Nesting: Dictionaries Inside Lists
One dictionary per student, all of them in a list — how real data looks.
- 06
Project: A Phone Book You Can Edit
Search, add, update and delete records — with no crash on a missing name.
Make It Survive the Restart
Until now everything your programs knew was forgotten the moment they closed. Read text from disk, write it back, process a file line by line, store records you can load again, and handle the file that is not there.
What you should already know
- Basics only: variables,
print(),if/else, andforloops. - Helpful but not required: Sections 2 and 3 — records are usually read into lists and dictionaries.
- 01
Reading a File:
openandwithThree ways to read, and the one line that closes the file for you.
- 02
Writing & Appending:
"w"vs"a"Save text to disk — and know which mode wipes the file.
- 03
Line by Line: strip, split, and Loops
Turn a text file into data you can actually work with.
- 04
Records: Saving a Table of Data
One line per record, split by commas — a CSV by hand.
- 05
When the File Is Missing
try/except FileNotFoundError, and checking before you open. - 06
Project: A Notebook That Remembers
Write notes, list them, delete one — all still there tomorrow.
Your Own Kind of Thing
Stop juggling parallel lists of names, scores and lives. Write a blueprint once, then make as many objects from it as you like — each with its own data and its own behaviour. Six lessons from the first class to a family of them.
What you should already know
- Basics: variables,
if/else, loops. - Section 1 · Functions is required here — a method is a function that lives on a class, so
def, parameters andreturnmust already be familiar. - Helpful: Sections 2 and 3 — a list of objects is the natural next step after a list of dictionaries.
- 01
Classes and Objects: The Blueprint Idea
One class, many objects — and what that actually buys you.
- 02
Attributes and
__init__Give every object its own data at the moment it is created.
- 03
Methods: Behaviour That Belongs to the Object
Functions with
self, and why that first parameter is there. - 04
Many Objects, One List
Build a list of objects and loop over it — the pattern behind every game.
- 05
Inheritance and
super()A new class that keeps everything the old one had, and changes one thing.
- 06
Project: A Class-Based Inventory
Items, quantities and behaviour in one place, instead of three lists.
Every Way to Handle Text
Text is the data you meet most and tidy up least. Reach into it by position, clean up whatever the user typed, split a sentence into words and join it back, and format numbers so a column of prices actually lines up.
What you should already know
- Basics only: variables,
input(),print(),if/else, andforloops. - Helpful but not required: Section 2 · Lists —
split()hands you a list, and lesson 3 does a lot with it.
- 01
Index and Slice: Reaching Into Text
Take one letter or a run of them, counting from either end.
- 02
Cleaning Up: strip, lower, upper, replace
Make messy typing safe to compare before your program trusts it.
- 03
splitandjoin: Text Becomes a ListTurn a sentence into words, work on the words, put it back together.
- 04
f-strings: Building Readable Output
Drop values straight into text, and line up a column of $ prices.
- 05
Searching & Checking:
in, find, startswith, isdigitAsk text what it holds before you act on it — no crash, no guessing.
- 06
Project: A Receipt Formatter
Messy order lines in, a tidy aligned receipt out.
Read the Error, Fix the Bug
A red wall of text is not a punishment — it is the most useful message Python ever gives you. Learn to read a traceback, catch the failures you can see coming, raise your own when the data is wrong, and stop a program crashing on a typo.
What you should already know
- Basics only: variables,
input(),if/else, and loops. - Nothing else. Take this one early — every other section is easier once you can read what went wrong.
- 01
Reading a Traceback
The last line names the problem, the rest tells you where it happened.
- 02
try/except: Catching What You ExpectHandle the failure you can see coming, and let the rest be loud.
- 03
The Five Errors You Will Actually Meet
ValueError,TypeError,IndexError,KeyError,ZeroDivisionError. - 04
else,finallyand Tidying UpRun something only when nothing failed — and something else regardless.
- 05
raise: Failing on PurposeReject bad data at the door instead of ten lines later.
- 06
Project: A Calculator That Never Crashes
Whatever the user types, it answers or explains — it never dies.
Write It the Python Way
The same job in one clear line instead of four. Comprehensions, enumerate, zip and key= are what separate code that merely works from code that reads like Python — and they appear in every codebase you will ever open.
What you should already know
- Basics: variables,
if/else, andforloops. - Section 2 · Lists is required here — every lesson builds or reshapes a list, so indexing and looping must already be comfortable.
- Helpful: Sections 1 and 3 —
lambdalands better afterdef, and lesson 5 builds dictionaries.
- 01
List Comprehensions: One Line, One Loop
The four-line loop that becomes one readable line.
- 02
Filtering: adding
ifInside a ComprehensionBuild and filter in a single pass, without an empty list first.
- 03
enumerateandzipLoop with the index, or over two lists at once — no counter variable.
- 04
lambda,mapandfilterTiny throwaway functions, and where they beat writing a whole one.
- 05
Dictionary Comprehensions and
sorted(key=)Reshape a dictionary, and sort anything by a rule you write.
- 06
Project: A Data Tidy-Up in Ten Lines
Take a messy record list and clean, filter and sort it — compactly.
The Other Two Containers
Lists and dictionaries are not the whole story. A tuple is the one that cannot change, which is exactly why it is safe; a set throws duplicates away and answers “what is in both?” instantly. Knowing which container to reach for is half of writing good Python.
What you should already know
- Basics: variables,
if/else, andforloops. - Section 2 · Lists is required here — every lesson compares the new container against a list.
- Helpful: Section 3 · Dictionaries — lesson 5 weighs all four side by side.
- 01
Tuples: The List That Cannot Change
Why a container you cannot edit is a feature, not a limitation.
- 02
Unpacking and Returning Several Values
One line for
a, b = b, a— and functions that answer twice. - 03
Sets: No Duplicates, No Order
Throw away repeats in one call, and test membership fast.
- 04
Set Maths: union, intersection, difference
Who is in both classes? Who is only in mine? One operator each.
- 05
Choosing: List, Tuple, Set or Dictionary
Four containers, one decision — with the questions that settle it.
- 06
Project: A Duplicate Finder
Two name lists in; the repeats, the uniques and the overlap out.
Split It Across Files
One file gets long, then unmanageable. Import what the standard library already gives you, move your own code into files you can reuse, understand why every real script ends with that __main__ line, and install someone else’s package without breaking your machine.
What you should already know
- Basics: variables,
if/else, and loops. - Section 1 · Functions is required here — a module is mostly a file of functions, so there must be something worth moving.
- 01
import: Using Code Somebody Else Wroterandom,math,datetime— batteries already included. - 02
Your Own Module: One File, Many Programs
Move your functions out, import them back, use them anywhere.
- 03
from ... import, aliases and Name ClashesThree ways to import, and the one that quietly overwrites things.
- 04
The
__main__Line, ExplainedWhy importing your file should not run it — and the one-line fix.
- 05
pipand Virtual EnvironmentsInstall a package for one project without touching the others.
- 06
Project: A Package of Your Own
Three modules, one folder, imported into a program that uses all three.