Guide 1 · Foundations

Python from the Start

The language, from nothing to writing your own modules. Every other guide depends on this one.

Complete 21 notebooks 21 written

Before this guide: None. If you have never written a line of code, start here.

The notebooks

Open in Colab runs a notebook in your browser, and Read shows it on GitHub without running it. Every notebook runs on its own, and the answers to its exercises are in a separate notebook, linked as Solutions.

1Running PythonColab, cells, print, and the read-eval loopOpen in ColabReadSolutions
2Values and VariablesAssignment, names, and what a variable actually isOpen in ColabReadSolutions
3Numbersint, float, integer division, and why 0.1 + 0.2 is not 0.3Open in ColabReadSolutions
4StringsSlicing, f-strings, methods, and immutabilityOpen in ColabReadSolutions
5Regular ExpressionsPatterns, groups, and the re moduleOpen in ColabReadSolutions
6Booleans and ComparisonTruthiness, and why `is` is not `==`Open in ColabReadSolutions
7ListsMutation, aliasing, and the copy that was not a copyOpen in ColabReadSolutions
8Tuples and UnpackingImmutability as a feature, and multiple return valuesOpen in ColabReadSolutions
9DictionariesThe workhorse. get, setdefault, and iteration orderOpen in ColabReadSolutions
10SetsMembership, deduplication, and set algebraOpen in ColabReadSolutions
11Conditionalsif, elif, else, and the guard clauseOpen in ColabReadSolutions
12Loopsfor, while, break, continue, enumerate, zipOpen in ColabReadSolutions
13ComprehensionsThe Python idiom, and when it stops being readableOpen in ColabReadSolutions
14FunctionsArguments, returns, and the mutable default argument trapOpen in ColabReadSolutions
15ScopeLocal, global, closures, and why your variable did not changeOpen in ColabReadSolutions
16Errors and ExceptionsReading a traceback, try/except, and raising your ownOpen in ColabReadSolutions
17Files and PathsReading, writing, context managers, pathlibOpen in ColabReadSolutions
18Modules and ImportsYour own modules, the import path, and `if __name__`Open in ColabReadSolutions
19Environments and pipvenv, requirements, and why the tutorial brokeOpen in ColabReadSolutions
20Debuggingprint, breakpoint, and reading the error you already haveOpen in ColabReadSolutions
21Where NextA map of the other guides, and what to read for whatOpen in ColabReadSolutions

Sources

Some of the ground this guide covers, including the way a variable is a name rather than a box and the several ways Python can be run, is shaped by A Whirlwind Tour of Python by Jake VanderPlas, released under a CC0 “No Rights Reserved” license. The explanations, examples and exercises here are written for this guide.