Intermediate Python
The next step after the basics: functions in depth, classes and objects, modules, error handling, comprehensions, generators, decorators and more.
You know variables, loops and functions; now learn to write Python the way experienced programmers do. Each lesson explains one idea with code you can run and change, then an exercise checks your answer. A project at the end puts it all together.
- 1Functions in depthUse default values safely, collect any number of arguments with args and kwargs, and force clear calls with keyword-only parameters.18 min
- 2Scope and closuresLearn how Python finds a name (local, enclosing, global, built-in), when to use global and nonlocal, and how closures let functions remember values.16 min
- 3Lambda, map, filter and sortedWrite small one-line functions with lambda and use them with sorted, min, max, map and filter to sort and transform data by any rule.15 min
- 4Comprehensions: list, dict and setBuild lists, dictionaries and sets in one readable line, filter with if, choose values with if/else, and handle nested data with nested loops.16 min
- 5Unpacking and the star operatorSplit tuples and lists into names in one line, catch the rest with a star, and use and to spread lists and dictionaries into calls.14 min
- 6Iterators and generatorsSee how for loops really work with iter and next, write generator functions with yield, and process big data one item at a time.18 min
- 7Modules and the standard libraryImport modules in different ways, split code into your own files, and use Counter, defaultdict, namedtuple and itertools from the standard library.18 min
- 8Exceptions in depthUse else and finally, create your own exception classes, chain errors with raise from, and clean up safely with the with statement.18 min
- 9Classes and objectsCreate your own types with class, set up objects with __init__, add methods that use self, and tell class attributes from instance attributes.18 min
- 10Inheritance and super()Build new classes on top of existing ones, override methods, reuse parent code with super(), and treat related objects the same way.16 min
- 11Special methods and dataclassesMake your objects print nicely, compare, sort and add up with special methods like __str__, __eq__ and __lt__, then let dataclasses write them for you.18 min
- 12DecoratorsUnderstand that functions are values, wrap them in other functions, and write decorators that log, count, repeat or cache function calls.17 min
- 13Type hintsAdd type hints to variables, functions and classes, describe lists, dictionaries and optional values, and let a checker find bugs before you run code.14 min
- 14Project: an inventory managerCombine dataclasses, custom exceptions, special methods, generators, a decorator and type hints in a small inventory program for a shop.25 min