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.

1 · 30 lessons

Python foundations

Values, strings, control flow, functions, data structures, errors, files, JSON and dates, then a small project.

  1. 1Values and names
  2. 2Printing output
  3. 3Strings and f-strings
  4. 4Numbers
  5. 5Comparisons and booleans
  6. 6Branching
  7. 7None, the missing value
  8. 8Indexing and slicing
  9. 9String methods
  10. 10Loops
  11. 11break, continue and else
  12. 12Functions
  13. 13Local and global scope
  14. 14Lists
  15. 15List methods and copies
  16. 16Tuples and unpacking
  17. 17Dicts and sets
  18. 18More comprehensions
  19. 19Grouping and counting
  20. 20Nested data
  21. 21Recursion
  22. 22Sorting with key and lambda
  23. 23Errors and try/except
  24. 24Raising your own exceptions
  25. 25Reading and writing files
  26. 26Paths and folders
  27. 27JSON files
  28. 28Dates and times
  29. 29math and random
  30. 30Project: a word report
2 · 30 lessons

Python deeper

Packages, how objects behave, classes in depth, iteration tools, errors, pattern matching, functools and typing.

  1. 1Modules and imports
  2. 2Packages
  3. 3Identity, equality and copies
  4. 4Bytes, str and Unicode
  5. 5Classes
  6. 6Inheritance and super()
  7. 7Equality, hashing and ordering
  8. 8Properties
  9. 9Class and static methods
  10. 10Dataclasses
  11. 11Slots
  12. 12Enums
  13. 13Protocols and duck typing
  14. 14Abstract base classes
  15. 15Composition and mixins
  16. 16Descriptors
  17. 17Class hooks and metaclasses
  18. 18Iterators and generators
  19. 19Sending into generators
  20. 20The itertools module
  21. 21Comprehensions and the walrus
  22. 22The collections module
  23. 23Context managers
  24. 24Exception chaining and groups
  25. 25Pattern matching
  26. 26Decorators
  27. 27Functions that return functions
  28. 28The functools module
  29. 29Typing
  30. 30Generic classes
3 · 15 lessons

Clean code in Python

Names, small functions, guard clauses, value objects and clear errors: refactor working code so others can read and change it.

  1. 1Names that say what they mean
  2. 2Small functions with one job
  3. 3One level of abstraction
  4. 4Guard clauses and early return
  5. 5Replacing flag arguments
  6. 6Constants and enums
  7. 7Comments versus clear code
  8. 8Duplication and when to remove it
  9. 9From primitives to value objects
  10. 10Prefer immutable values
  11. 11Pure functions, effects at the edges
  12. 12Exceptions instead of error codes
  13. 13One reason to change
  14. 14Open for extension
  15. 15Type hints as documentation
4 · 12 lessons

Testing in Python

Clear assertions, pytest discovery, fixtures and parametrize, then mocks, fakes, controlled time, property-style tests and doctest.

  1. 1Arrange, act, assert
  2. 2How pytest finds tests
  3. 3Fixtures
  4. 4Parametrize
  5. 5Testing exceptions in detail
  6. 6Files with tmp_path
  7. 7Mock and patch
  8. 8monkeypatch
  9. 9Fakes versus mocks
  10. 10Property-style tests by hand
  11. 11Doctest
  12. 12Testing a class through its behaviour
5 · 15 lessons

Tools you work with

Tests, tracebacks, debugging, linting and profiling, then command lines, files, regexes, settings, SQLite and packages.

  1. 1Writing tests
  2. 2Reading a traceback
  3. 3Using the debugger
  4. 4Logging
  5. 5Linting with pyflakes
  6. 6Timing with timeit
  7. 7Profiling with cProfile
  8. 8Command-line programs
  9. 9Tidying files with pathlib
  10. 10Searching text with re
  11. 11Settings from the environment
  12. 12SQLite for everyday data
  13. 13Virtual environments
  14. 14Packaging and pyproject
  15. 15Requirements and versions
6 · 15 lessons

Architecture in Python

Layers, ports and adapters, repositories, services and events: structure an application so each part can be tested alone.

  1. 1Layers and import direction
  2. 2Functional core, imperative shell
  3. 3Dependency inversion
  4. 4Entities and value objects
  5. 5A state machine for a workflow
  6. 6The repository pattern
  7. 7A service layer
  8. 8Unit of work
  9. 9Domain events and handlers
  10. 10Commands and queries
  11. 11Ports and adapters
  12. 12Errors at layer boundaries
  13. 13Caching behind an interface
  14. 14Plugin registries
  15. 15Configuration and wiring
7 · 12 lessons

Concurrency and async

Threads, pools, locks and queues, then asyncio: tasks, timeouts, task groups, rate limits, async iterators and to_thread.

  1. 1Threads and join
  2. 2Thread pools and futures
  3. 3Race conditions and locks
  4. 4Queues for producers and consumers
  5. 5async and await
  6. 6Tasks and gather
  7. 7Timeouts and cancellation
  8. 8TaskGroup and structured concurrency
  9. 9Semaphores and rate limits
  10. 10Async generators and async for
  11. 11Async context managers
  12. 12Blocking code and to_thread
8 · 5 lessons

Web and backend

HTTP, JSON, URLs, WSGI, Flask and how Django routes requests.

  1. 1HTTP and JSON
  2. 2Parsing a URL
  3. 3WSGI
  4. 4Flask routes
  5. 5How Django routes URLs
9 · 4 lessons

Data and notebooks

NumPy arrays, aggregates, cleaning CSV data and reproducible runs.

  1. 1NumPy arrays
  2. 2Broadcasting and aggregates
  3. 3CSV and cleaning data
  4. 4Reproducibility with seeds
10 · 18 lessons

Machine learning with PyTorch

Tensors, autograd and training loops, then classifiers, convolutions, attention and a tiny language model, trained on the device.

  1. 1Tensors
  2. 2Autograd
  3. 3Gradient descent
  4. 4Modules and optimizers
  5. 5Your own module
  6. 6Classification
  7. 7Training, test and overfitting
  8. 8Dropout and weight decay
  9. 9Mini-batches
  10. 10Your own Dataset
  11. 11Batch normalisation
  12. 12Learning-rate schedules
  13. 13Gradient clipping
  14. 14Checkpoints and early stopping
  15. 15Convolutions
  16. 16Recurrent networks
  17. 17Attention
  18. 18A tiny language model
11 · 9 lessons

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.

  1. 1Tokens
  2. 2Embeddings
  3. 3Retrieval
  4. 4Sampling
  5. 5A self-attention layer
  6. 6The transformer block
  7. 7A tiny GPT
  8. 8Fine-tuning with LoRA
  9. 9Measuring a language model
12 · 3 lessons

Working with AI tools

Validating model output, modelling tool calls and reviewing generated code.

  1. 1Structured output
  2. 2Tool calling
  3. 3Reviewing AI-written code
Practice · 20 tasks

Interview practice

Twenty timed coding problems, from warm-ups to hard.

  1. 1Rotate a listEasy · 10 min
  2. 2Balanced bracketsEasy · 15 min
  3. 3First character seen onceEasy · 10 min
  4. 4A pair that hits the targetEasy · 15 min
  5. 5Palindrome through the noiseEasy · 15 min
  6. 6The shared defaultEasy · 10 min
  7. 7Closures in a loopEasy · 10 min
  8. 8Merge intervalsMedium · 20 min
  9. 9Group by lettersMedium · 20 min
  10. 10Longest run with no repeatsMedium · 25 min
  11. 11Count pairs below a limitMedium · 20 min
  12. 12Tree level by levelMedium · 20 min
  13. 13Fewest hopsMedium · 20 min
  14. 14Count connected groupsMedium · 20 min
  15. 15Exact changeMedium · 25 min
  16. 16Tiling with memoizationMedium · 20 min
  17. 17Cheapest routeHard · 35 min
  18. 18Edit distanceHard · 35 min
  19. 19Best path in a treeHard · 40 min
  20. 20Limit concurrent jobsHard · 40 min