The language, from nothing to writing your own modules. Every other guide depends on this one.
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.
| 1 | Running PythonColab, cells, print, and the read-eval loop | Open in ColabReadSolutions |
| 2 | Values and VariablesAssignment, names, and what a variable actually is | Open in ColabReadSolutions |
| 3 | Numbersint, float, integer division, and why 0.1 + 0.2 is not 0.3 | Open in ColabReadSolutions |
| 4 | StringsSlicing, f-strings, methods, and immutability | Open in ColabReadSolutions |
| 5 | Regular ExpressionsPatterns, groups, and the re module | Open in ColabReadSolutions |
| 6 | Booleans and ComparisonTruthiness, and why `is` is not `==` | Open in ColabReadSolutions |
| 7 | ListsMutation, aliasing, and the copy that was not a copy | Open in ColabReadSolutions |
| 8 | Tuples and UnpackingImmutability as a feature, and multiple return values | Open in ColabReadSolutions |
| 9 | DictionariesThe workhorse. get, setdefault, and iteration order | Open in ColabReadSolutions |
| 10 | SetsMembership, deduplication, and set algebra | Open in ColabReadSolutions |
| 11 | Conditionalsif, elif, else, and the guard clause | Open in ColabReadSolutions |
| 12 | Loopsfor, while, break, continue, enumerate, zip | Open in ColabReadSolutions |
| 13 | ComprehensionsThe Python idiom, and when it stops being readable | Open in ColabReadSolutions |
| 14 | FunctionsArguments, returns, and the mutable default argument trap | Open in ColabReadSolutions |
| 15 | ScopeLocal, global, closures, and why your variable did not change | Open in ColabReadSolutions |
| 16 | Errors and ExceptionsReading a traceback, try/except, and raising your own | Open in ColabReadSolutions |
| 17 | Files and PathsReading, writing, context managers, pathlib | Open in ColabReadSolutions |
| 18 | Modules and ImportsYour own modules, the import path, and `if __name__` | Open in ColabReadSolutions |
| 19 | Environments and pipvenv, requirements, and why the tutorial broke | Open in ColabReadSolutions |
| 20 | Debuggingprint, breakpoint, and reading the error you already have | Open in ColabReadSolutions |
| 21 | Where NextA map of the other guides, and what to read for what | Open 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.