Learn Python
Every lesson runs in this browser with Pyodide 314.0.7 · Python 3.14.2. Read a part, try the examples, then write the solution and check it with the same checks the app uses.
Progress and your code are kept in this browser only.
Python foundations
Values, strings, control flow, functions, data structures, errors, files, JSON and dates, then a small project.
- 1Values and names
- 2Printing output
- 3Strings and f-strings
- 4Numbers
- 5Comparisons and booleans
- 6Branching
- 7None, the missing value
- 8Indexing and slicing
- 9String methods
- 10Loops
- 11break, continue and else
- 12Functions
- 13Local and global scope
- 14Lists
- 15List methods and copies
- 16Tuples and unpacking
- 17Dicts and sets
- 18More comprehensions
- 19Grouping and counting
- 20Nested data
- 21Recursion
- 22Sorting with key and lambda
- 23Errors and try/except
- 24Raising your own exceptions
- 25Reading and writing files
- 26Paths and folders
- 27JSON files
- 28Dates and times
- 29math and random
- 30Project: a word report
Python deeper
Packages, how objects behave, classes in depth, iteration tools, errors, pattern matching, functools and typing.
- 1Modules and imports
- 2Packages
- 3Identity, equality and copies
- 4Bytes, str and Unicode
- 5Classes
- 6Inheritance and super()
- 7Equality, hashing and ordering
- 8Properties
- 9Class and static methods
- 10Dataclasses
- 11Slots
- 12Enums
- 13Protocols and duck typing
- 14Abstract base classes
- 15Composition and mixins
- 16Descriptors
- 17Class hooks and metaclasses
- 18Iterators and generators
- 19Sending into generators
- 20The itertools module
- 21Comprehensions and the walrus
- 22The collections module
- 23Context managers
- 24Exception chaining and groups
- 25Pattern matching
- 26Decorators
- 27Functions that return functions
- 28The functools module
- 29Typing
- 30Generic classes
Clean code in Python
Names, small functions, guard clauses, value objects and clear errors: refactor working code so others can read and change it.
- 1Names that say what they mean
- 2Small functions with one job
- 3One level of abstraction
- 4Guard clauses and early return
- 5Replacing flag arguments
- 6Constants and enums
- 7Comments versus clear code
- 8Duplication and when to remove it
- 9From primitives to value objects
- 10Prefer immutable values
- 11Pure functions, effects at the edges
- 12Exceptions instead of error codes
- 13One reason to change
- 14Open for extension
- 15Type hints as documentation
Testing in Python
Clear assertions, pytest discovery, fixtures and parametrize, then mocks, fakes, controlled time, property-style tests and doctest.
Tools you work with
Tests, tracebacks, debugging, linting and profiling, then command lines, files, regexes, settings, SQLite and packages.
- 1Writing tests
- 2Reading a traceback
- 3Using the debugger
- 4Logging
- 5Linting with pyflakes
- 6Timing with timeit
- 7Profiling with cProfile
- 8Command-line programs
- 9Tidying files with pathlib
- 10Searching text with re
- 11Settings from the environment
- 12SQLite for everyday data
- 13Virtual environments
- 14Packaging and pyproject
- 15Requirements and versions
Architecture in Python
Layers, ports and adapters, repositories, services and events: structure an application so each part can be tested alone.
- 1Layers and import direction
- 2Functional core, imperative shell
- 3Dependency inversion
- 4Entities and value objects
- 5A state machine for a workflow
- 6The repository pattern
- 7A service layer
- 8Unit of work
- 9Domain events and handlers
- 10Commands and queries
- 11Ports and adapters
- 12Errors at layer boundaries
- 13Caching behind an interface
- 14Plugin registries
- 15Configuration and wiring
Concurrency and async
Threads, pools, locks and queues, then asyncio: tasks, timeouts, task groups, rate limits, async iterators and to_thread.
- 1Threads and join
- 2Thread pools and futures
- 3Race conditions and locks
- 4Queues for producers and consumers
- 5async and await
- 6Tasks and gather
- 7Timeouts and cancellation
- 8TaskGroup and structured concurrency
- 9Semaphores and rate limits
- 10Async generators and async for
- 11Async context managers
- 12Blocking code and to_thread
Web and backend
HTTP, JSON, URLs, WSGI, Flask and how Django routes requests.
Data and notebooks
NumPy arrays, aggregates, cleaning CSV data and reproducible runs.
Machine learning with PyTorch
Tensors, autograd and training loops, then classifiers, convolutions, attention and a tiny language model, trained on the device.
- 1Tensors
- 2Autograd
- 3Gradient descent
- 4Modules and optimizers
- 5Your own module
- 6Classification
- 7Training, test and overfitting
- 8Dropout and weight decay
- 9Mini-batches
- 10Your own Dataset
- 11Batch normalisation
- 12Learning-rate schedules
- 13Gradient clipping
- 14Checkpoints and early stopping
- 15Convolutions
- 16Recurrent networks
- 17Attention
- 18A tiny language model
AI: language models from the inside
Tokens, embeddings, retrieval, sampling, attention and transformer blocks, then a tiny GPT trained on the device, LoRA fine-tuning and perplexity.
Working with AI tools
Validating model output, modelling tool calls and reviewing generated code.
Interview practice
Twenty timed coding problems, from warm-ups to hard.
- 1Rotate a list
- 2Balanced brackets
- 3First character seen once
- 4A pair that hits the target
- 5Palindrome through the noise
- 6The shared default
- 7Closures in a loop
- 8Merge intervals
- 9Group by letters
- 10Longest run with no repeats
- 11Count pairs below a limit
- 12Tree level by level
- 13Fewest hops
- 14Count connected groups
- 15Exact change
- 16Tiling with memoization
- 17Cheapest route
- 18Edit distance
- 19Best path in a tree
- 20Limit concurrent jobs