Python

Python is widely used to explore machine learning. Here, you will write small programs, inspect their results, and build numerical experiments. Previous programming experience helps, but the opening chapters begin with the basics.

A program is a precise way to test an idea. Python gives us a compact way to write that test and see the result. Throughout this subject, the examples stay small enough to read, run, and change.

The first half develops everyday Python: values, decisions, loops, functions, collections, errors, files, and simple records. The second half turns to numerical work with NumPy, array calculations, plots, randomness, and a complete experiment.

Do not try to memorize every detail on the first pass. Predict what a short program will do, run it, compare the result with your prediction, and then change one thing. When an error appears, treat it as evidence about what the program expected.

Chapters

If Python is new to you, begin with Chapter 1 and follow the sequence. If you already use Python, begin with the first chapter whose examples are unfamiliar.

Chapter 1Getting Started with Python

What programming and Python are, how to run a small program, and how to inspect its output and errors.

7 lessons23 exercises
Chapter 2Names, Values, and Types

Learn how names refer to values, how expressions produce results, and how types determine which operations make sense.

6 lessons35 exercises
Chapter 3Branches and Loops

Choose between actions with branches, repeat work with loops, maintain totals, and check loop boundaries.

6 lessons34 exercises
Chapter 4Functions

Define readable Python functions, trace arguments and scope, add basic type hints, return results, use defaults, and check behavior with tests.

7 lessons40 exercises
Chapter 5Collections and Iteration

Choose and use Python collections, iterate over values, select sequence ranges, transform data, and reason about mutation and copying.

7 lessons47 exercises
Chapter 6Errors and Debugging

Read Python tracebacks, diagnose common exceptions, handle expected failures, test assumptions, and reduce bugs systematically.

8 lessons50 exercises
Chapter 7Files, Paths, and Modules

Learn how Python programs read and write text files, build portable paths, manage project environments, reuse modules, define script entry points, and organize a small project.

7 lessons47 exercises
Chapter 8Objects, Records, and Type Hints

Organize related values with attributes, classes, and dataclasses, then document and statically check function interfaces.

6 lessons44 exercises
Chapter 9NumPy Arrays

Create NumPy arrays and reason about their shape, data type, axes, indexing, views, copies, and common errors.

7 lessons45 exercises
Chapter 10Array Computation

Compute with whole NumPy arrays using elementwise operations, Boolean masks, broadcasting, centering, vectorization, and matrix products while tracking values, axes, dtypes, and shapes.

7 lessons48 exercises
Chapter 11Plotting and Inspection

Use Matplotlib to inspect numerical data, distributions, arrays, loss surfaces, and computational mistakes.

9 lessons55 exercises
Chapter 12Randomness and Reproducibility

Generate, sample, shuffle, and split data while recording enough evidence to reproduce and compare randomized computations.

7 lessons45 exercises
Chapter 13A Small Numerical Project

Build a complete Python project that generates noisy data, fits a line, inspects the evidence, and records a reproducible result.

7 lessons45 exercises

Subject progress