Skip to content
All courses
PythonIntermediate

Intermediate Python

Go beyond the basics: tuples and sets, comprehensions, flexible functions, error handling, classes, dataclasses and generators, all practised in real Python in your browser.

Recommended first: Python Fundamentals. This course builds on it.

Free to browse. You sign in at the first lesson so your progress is saved.

What you will be able to do

  • Group and compare data with tuples, sets and unpacking
  • Write clear one-line transformations with comprehensions
  • Build flexible functions with *args, **kwargs, key functions and closures
  • Handle errors with try and except, and raise your own exceptions
  • Model real things with classes, inheritance, dataclasses and generators

Syllabus

7 modules and 24 lessons. Each lesson is a short read followed by an exercise with tests.

Module 1

Tuples, sets and unpacking

Group fixed values with tuples, pull them apart with unpacking and remove duplicates with sets.3 lessons, about 40 min
  1. 1TuplesStore a fixed group of related values that should not change.12 min
  2. 2Unpacking valuesPull the items out of a tuple into separate variables in one line.14 min
  3. 3SetsKeep only unique values and compare groups with union, intersection and difference.14 min
Module 2

Comprehensions

Build lists, dictionaries and sets in a single readable line, and total up data without building lists at all.3 lessons, about 43 min
  1. 4List comprehensionsBuild a new list from an existing one in a single expression.15 min
  2. 5Dict and set comprehensionsUse the same one-line pattern to build dictionaries and sets.14 min
  3. 6Generator expressionsFeed values straight into sum, max, any and all without building a list first.14 min
Module 3

Functions in depth

Accept any number of arguments, force clear keyword calls, sort with key functions and build functions that remember.4 lessons, about 1 hour
  1. 7Any number of argumentsCollect extra positional arguments into a tuple with *args.14 min
  2. 8Keyword argumentsCollect named arguments with **kwargs and make some arguments keyword-only.16 min
  3. 9Sorting with a keyUse lambda functions to control how sorted, min and max compare items.16 min
  4. 10Functions that rememberReturn a function that keeps hold of values from where it was made.18 min
Module 4

Errors and exceptions

Handle problems without crashing, tidy up whatever happens, raise clear errors and define your own.4 lessons, about 1 hour
  1. 11Catching errorsUse try and except to handle a problem instead of crashing.15 min
  2. 12else and finallyRun code only when nothing failed, and run tidy-up code whatever happens.14 min
  3. 13Raising exceptionsStop with a clear error when your function is given bad data.15 min
  4. 14Custom exceptionsDefine your own exception types so callers can catch exactly your errors.16 min
Module 5

Classes and objects

Bundle data and behaviour into your own types, give them readable output and share values between objects.4 lessons, about 1 hour
  1. 15Your first classDefine a class with __init__ and create objects from it.16 min
  2. 16MethodsGive objects behaviour by adding functions to the class.16 min
  3. 17Printing objects clearlyControl how your objects look with __str__ and __repr__.15 min
  4. 18Class and instance attributesShare a value between every object of a class, and avoid the shared list trap.16 min
Module 6

Inheritance, composition and dataclasses

Reuse code by extending classes or combining objects, and skip the boilerplate with dataclasses.3 lessons, about 52 min
  1. 19InheritanceBuild a new class on top of an existing one and extend its behaviour.18 min
  2. 20CompositionBuild objects out of other objects when one thing has another.16 min
  3. 21DataclassesLet Python write __init__, __repr__ and __eq__ for classes that mainly hold data.18 min
Module 7

Iterators and generators

See how for loops really work, write functions that yield values one at a time and chain them into pipelines.3 lessons, about 48 min
  1. 22How for loops workStep through any collection by hand with iter() and next().14 min
  2. 23Generator functionsWrite functions that yield values one at a time with the yield keyword.16 min
  3. 24Generator pipelinesChain generators so each stage handles one item at a time, even from an endless source.18 min

After this course

Where to go next

These courses build on what you learn in Intermediate Python.

  • PythonIntermediate

    Python Project: A Basket Summary

    Build a basket summary in integer pence, account for unavailable products and package the calculation in a reusable function.

    Recommended first: Intermediate Python

    • 3 lessons
    • About 1 hour
  • PythonIntermediate

    Working with Data in Python

    Clean, read, count and report on everyday data using only the Python standard library: text, CSV, JSON, dates and tidy text reports.

    Recommended first: Intermediate Python

    • 21 lessons
    • About 5 hours