- Write and run a program that shows text on the screen
- Tell the difference between text and numbers
- Leave notes in your code with comments
- Read an error message and fix the mistake it points to
The course
Python, from zero to advanced
Forty units in four parts. Work through them in order: each unit's checkpoint opens the next one. Already know a topic? Take its checkpoint to test out.
All 40 units open
201 lessons
405 checked exercises
About 55.1 hrs at a steady pace
Foundations
From your very first line to programs that make decisions, repeat themselves and are built from functions.
- Store a value in a variable and use it later
- Change a variable, including by using its old value
- Choose names that are allowed and easy to understand
- Trace a program, keeping track of every variable as it changes
- Use + - * / and know why / always gives a decimal
- Use // and % to split things into whole parts and remainders
- Predict the order Python works a calculation out in, and control it with brackets
- Round, compare and update numbers with Python's built-in tools
- Join strings with + and convert numbers with str()
- Build tidy output with f-strings, including rounding inside them
- Pick out characters and slices by their position
- Change and search text with string methods
- Ask the user a question with input() and use the answer
- Explain why input() always gives text, and convert it with int() and float()
- Check what type a value is with type()
- Build a complete interactive program from small steps
- Compare values and get True or False
- Run code only when a condition is true, with if
- Choose between several options with elif and else
- Combine conditions with and, or and not
- Repeat a block of code with while
- Count, add up and track values across repetitions
- Keep asking for input until it is valid or the user says stop
- Leave a loop early with break, and skip ahead with continue
- Loop over every character in a string
- Count with range(), including custom starts and steps
- Use the classic loop patterns: count, total, biggest, and find
- Put one loop inside another to make grids and patterns
- Create a list and read items by position
- Add, insert, remove and change items
- Loop over a list to total, count, filter and find
- Sort a list, and split text into a list of words
- Tell when two names share one list, and make real copies
- Define a function with def and call it
- Pass information in with parameters
- Give an answer back with return, and know when to print instead
- Use defaults and local variables, and build programs from small functions
Working with data
Text, collections, files and errors: the everyday tools for programs that handle real information.
- Use escape characters and multi-line strings
- Check what text contains with methods like isdigit and isalpha
- Pull structured text apart with split, strip and partition
- Line output up in columns with format specifiers
- Work with character codes using ord and chr
- Work with character codes, binary, hex and bytes
- Create tuples and know when to use one instead of a list
- Unpack values into several variables at once
- Return more than one value from a function
- Loop with positions using enumerate, and over pairs using zip
- Store and look up values by key in a dictionary
- Add, change and remove entries, and avoid KeyError with get
- Loop over keys, values and items
- Count things with a dictionary, and work with lists of dictionaries
- Create sets and use them to remove duplicates
- Add and remove items, and test membership
- Combine sets with union, intersection and difference
- Choose between a list, a set and a dictionary
- Turn a build-a-list loop into a list comprehension
- Filter items with if inside a comprehension
- Write dictionary and set comprehensions
- Use generator expressions with sum, any and all, and know when a loop reads better
- Call functions with keyword arguments and avoid the mutable default trap
- Accept any number of arguments with *args and **kwargs
- Pass functions to other functions, including to sorted, min and max with key
- Write small functions with lambda, and document functions with docstrings
- Catch errors with try and except, and only the ones you expect
- Use the error object, else and finally
- Raise your own errors when a function is given bad values
- Write input loops that survive anything the user types
- Open, read and loop over the lines of a text file
- Write and append to files, using with so they are always closed
- Read and write CSV data with the csv module
- Handle missing files gracefully
- Import modules in the different ways Python allows
- Use statistics, random and datetime to save writing code yourself
- Count and group with Counter and defaultdict
- Know where to look when you need a tool you haven't met
- Write your own modules that also work as programs
- Read a multi-line traceback and find the line that matters
- Find bugs with print statements, tracing and small test cases
- Recognise the most common bugs on sight
- Break a problem into small functions and build it step by step
Building bigger programs
Objects, recursion, algorithms and testing: how working programmers organise code that keeps growing.
- Explain what a class and an object are, and why they help
- Write a class with __init__ and attributes
- Add methods that use and change an object's data
- Design a small class and use several objects together
- Control how objects print with __str__ and __repr__
- Make objects work with ==, <, len and + using special methods
- Build a class on top of another with inheritance and super()
- Treat different kinds of object the same way, and know when to use composition instead
- Use class attributes, properties and class methods
- Write a recursive function with a base case and a recursive case
- Explain the call stack, and why missing base cases cause RecursionError
- Solve problems on nested data that loops struggle with
- Decide when recursion is clearer than a loop, and when it isn't
- Write a linear search and a binary search
- Explain why binary search needs sorted data and why it is so fast
- Count the steps an algorithm takes as its input grows
- Use Big-O names for common growth rates, and pick faster approaches
- Write selection sort and insertion sort, and trace them by hand
- Write merge sort, using recursion to split and merge
- Compare their speed with Big-O
- Sort real data with sorted, key functions and multiple criteria
- Use a stack for last-in, first-out problems like matching brackets and undo
- Use a queue, with collections.deque, for first-in, first-out problems
- Build a linked list from nodes, and walk, add to and search it
- Choose a structure by the operations a problem needs
- Explain how hash tables make dictionaries and sets fast
- Use a dictionary to remember what you've seen and turn O(n²) into O(n)
- Solve problems on sorted data with two pointers
- Keep a running window over a sequence instead of recomputing it
- Answer range-sum questions instantly with prefix sums
- Write test functions full of asserts, and run them
- Think of the edge cases that catch real bugs
- Use Python's unittest module
- Write tests first, then the code that passes them
- Explain what a for loop does underneath, with iter and next
- Write generator functions with yield
- Use generators to handle sequences too big, or endless, to store
- Combine and slice sequences with itertools
- Turn a description into a design: which classes, what they know, what they do
- Build a program with several cooperating classes, one step at a time
- Define your own exception type for errors that belong to your program
- Protect the finished program with tests
Advanced Python
Decorators, data structures, dynamic programming and clean design, ending with a capstone and life beyond the browser.
- Define functions inside functions and return them
- Explain closures: inner functions that remember variables from where they were made
- Write decorators that add behaviour to any function
- Use functools.wraps and the built-in lru_cache decorator
- Explain what with does, and why it is safer than try/finally by hand
- Write a context manager class with __enter__ and __exit__
- Write one more simply with contextlib.contextmanager
- Use the context managers in the standard library
- Add type hints to variables, parameters and return values
- Read hints for lists, dictionaries, optional values and unions
- Define data classes with defaults, ordering and immutability
- Use enums for fixed sets of named values
- Handle different forms of data with match and case
- Represent a tree with node objects that hold children
- Traverse a binary tree in pre-order, in-order and post-order, and by levels
- Build and search a binary search tree
- Measure trees recursively: size, height, sum
- Represent a graph as an adjacency list
- Explore a graph with depth-first and breadth-first search
- Find shortest paths, with BFS for steps and Dijkstra's algorithm for distances
- Treat grids and mazes as graphs
- Recognise overlapping subproblems, and fix them with memoisation
- Build answers bottom-up in a table instead
- Solve classic problems: stairs, coins, grid paths, common subsequences, knapsack
- Follow a method for turning a problem into a recurrence
- Write patterns with character classes, anchors and repetition
- Search, find all and replace with the re module
- Extract parts of a match with groups
- Validate input with fullmatch, and know when a regex is the wrong tool
- Convert between Python data and JSON text, and read and write JSON files
- Navigate and reshape nested data like the responses web services send
- Create a SQLite database and insert, query, sort and filter rows
- Summarise and combine tables with GROUP BY and JOIN, using parameters safely
- Choose names that explain what values and functions mean
- Keep functions small, flat and focused on one job
- Follow the PEP 8 style that Python programmers expect
- Refactor messy code safely, keeping its behaviour identical
- Build a complete, tested program from data classes, validation, files and reports
- Install Python and run programs on your own computer
- Use a terminal, a code editor, pip, virtual environments and git
- Choose what to learn and build next