Learn Python: Free Python Tutorial in 134 Lessons

Learn Python free: 134 lessons in 20 modules, from first programs to interview questions, with exercises judged on CPython 3.11 and a certificate.

  • Language: Python
  • Runtime: CPython 3.11
  • Modules: 20
  • Lessons: 134
  • Reading time: about 34 hours
  • Cost: Free on every plan, with a certificate

The language of data, scripting and the fastest interview rounds — the object model, comprehensions and generators, classes and the data model, exceptions, the standard library, typing, concurrency and performance — with exercises judged on a real CPython 3.11.

Syllabus

Module 1: Python and the interpreter

What CPython is and how it runs a file, the REPL, scripts and -m, the anatomy of a program, the console I/O patterns every exercise uses, and how to read a syntax error and a traceback.

Module 2: Values, types and operators

Arbitrary-precision integers and floor division, floating point and the rules for comparing and printing it, truthiness and what and/or return, names bound to objects, explicit conversions and their errors, and operator precedence with the bitwise idioms.

Module 3: Control flow

if/elif/else and guard clauses, while with break, continue and else, for over any iterable with range, enumerate and zip, structural pattern matching with match, and the loop patterns interviews are built from.

Module 4: Functions

def and return, the full signature with defaults, *args, **kwargs and keyword-only parameters, LEGB scope with closures and late binding, recursion with memoisation, lambdas and the key-function idiom, and the type hints and docstrings that publish a function's contract.

Module 5: Strings and text

Strings as immutable sequences, slicing and the method set, f-strings and the format-spec mini-language, code points versus bytes with the digit tests, the parsing shapes for every input format, and regular expressions with groups and substitution.

Module 6: Lists, tuples and sequences

Lists and their method costs, aliasing and copying, comprehensions in every form, sorting with keys, stability and bisect, tuples with unpacking and namedtuple, grids with neighbours and transposes, and the sequence tools with deque and the sequence protocol.

Module 7: Dictionaries and sets

Dictionaries with get, setdefault, views and merging, counting and grouping with Counter and defaultdict, sets and their algebra, the hashing contract that decides what can be a key, nested data and JSON, and the complexity table with heapq.

Module 8: Classes and objects

The class statement with __init__ and self, instance versus class attributes, the dunder methods that make a class behave like a built-in, @property and __slots__, class methods as alternative constructors, dataclasses and their options, and the design discipline of invariants and small interfaces.

Module 9: Inheritance, protocols and duck typing

Subclassing with super() and attribute lookup, duck typing with EAFP, abstract base classes and collections.abc, multiple inheritance with the MRO and mixins, typing.Protocol for structural typing, and composition over inheritance with Liskov, delegation and UserDict.

Module 10: Errors and exceptions

The try statement with else and finally, the hierarchy and matching, raise and chaining, custom exception classes, EAFP with suppress and sentinels, context managers as classes and generators, exception groups with except* and add_note, and assertions versus boundary validation.

Module 11: Iterators, generators and itertools

The iteration protocol with iter, next and StopIteration, generators with yield and yield from, generator expressions and the short-circuit consumers, the itertools toolkit, functools and operator, and lazy pipelines of generator stages.

Module 12: Modules, packages and imports

What import does and the sys.modules cache, from-imports copying bindings, packages with __init__.py and relative imports, the standard-library map, virtual environments with pip and pyproject.toml, and command-line scripts with argparse, streams and exit codes.

Module 13: The standard library in depth

math, statistics, Fraction, Decimal and seeded random; datetime arithmetic, parsing and time zones with zoneinfo; deque, Counter, OrderedDict, ChainMap and namedtuple in depth; textwrap, difflib, Template and the deeper re; and enums with auto, IntEnum, StrEnum and Flag.

Module 14: Files and data formats

open with modes, encodings and with; pathlib for building, querying and listing paths; CSV with DictReader/DictWriter; JSON with custom encoders and dataclass round trips; bytes with struct, byte order, base64 and hashlib; and sqlite3 with parameters, transactions and aggregation.

Module 15: Type hints and code quality

The hint vocabulary from generics and unions to TypeVar, Generic, Literal and TypedDict; what a type checker verifies and how narrowing works; PEP 8 layout, naming and docstrings with ruff and black; logging with levels, loggers, handlers and formats; and the idioms that make code Pythonic.

Module 16: Decorators, descriptors and the data model

Decorators as functions wrapping functions with wraps, arguments and stacking; closures with cells, late binding and factories; the descriptor protocol behind properties and methods; the attribute hooks and reflection; classes as objects with type, __new__ and __init_subclass__; and the rest of the data model through a Vector.

Module 17: Concurrency — threads, processes and asyncio

The GIL and the CPU-bound/I/O-bound decision; threads with Lock, Queue and Event and the race you must see once; concurrent.futures executors with ordered map; multiprocessing with pickling and the main guard; asyncio from coroutines and gather to TaskGroup, semaphores and queues; and the determinism rule for every concurrent program.

Module 18: Testing and debugging

The testing mindset and designing for testability; unittest with its assertion family, fixtures, subTest and in-process runs; pytest's fixtures and parametrize and the mechanisms behind them; test doubles with Mock, side_effect and patch; and debugging by reading tracebacks, logging, pdb and the reproduce–minimise–bisect method.

Module 19: Memory, performance and the interpreter

The object model with reference counting and the cycle collector; the cost model of the built-in operations; bytecode, code objects and the 3.11 specialising interpreter; measuring with timeit, cProfile and tracemalloc; numeric performance with array, bytes and NumPy; and the checklist for writing fast Python.

Module 20: Interview idioms

The round and the file template with fast I/O, the idiom sheet of shapes and their Python, the twelve pitfalls interviewers watch for, a hash map, dynamic array, LRU cache and heap by hand, clean solutions under pressure, and the Python theory drill.