Section · language
Python
The language of scripts, data and AI. Go from the first run to modules and classes: one idea per chapter, a working result first, then how it works. Practice is one-evening tasks for your own computer, server and network.
OverviewPython: where it came from, why it became the language of AI, and where to start13 chapters · 5 parts7 of 13 written
Dark — read, light — written, empty — in progress. Marks stay in this browser only.Chapters
Part 1
Basics
Run Python and see what a value is made of.read1You stopped hereRunning: the REPL and a
.py fileCalculate in interactive Python and run your first file.2You stopped hereVariables and typesName, value and type: what exactly a variable holds.3You stopped hereNumbersIntegers without a limit, fractions with an error: why 0.1 + 0.2 is not 0.3.4You stopped hereStringsSlices, methods and f-strings: get the date and extension out of a file name.Part 2
Program flow
Decisions, repetition and your own functions.readPart 3
Data
Collections of values: in order and by key.read8soonLists and tuplesFive ping times: the worst, the best, the median — and why the average lies.
9soonDictionaries and setsLookup by key in one step and counting without repeats.
Part 4
Files and errors
Working with the disk and with what goes wrong.read10soonFiles and paths
pathlib and with open: read, write, walk a folder.11soonErrors and exceptionsRead a traceback and catch only the errors you expect.
Part 5
Bigger code
Other people’s code from packages and your own data types.read12soonModules and packages
import, pip and virtual environments.13soonClassesYour own data type: when a class is needed and when a dictionary is enough.
Practice: one-evening tasks
A working script for a task of your own. Start here if you like: each manual explains what it needs, the chapters go deeper.
Python from scratch: install it and send files to your phone over Wi-FiBuilds on chapters: 1A 120-bit password from your own script: the first .py file and the secrets moduleBuilds on chapters: 1, 2, 3, 7Duplicate photos by content: a hash and a dictionary as memoryBuilds on chapters: 4, 6, 7, 9, 10Sort Downloads into folders: a script with a dry runBuilds on chapters: 1, 2, 5, 6, 9, 10What’s taking up disk space: the biggest files in one scriptBuilds on chapters: 4, 5, 6, 7, 8, 10Are the sites up: a list check and errors handled with try/exceptBuilds on chapters: 3, 4, 6, 7, 11A QR code for guest Wi-Fi: your first pip package in a virtual environmentBuilds on chapters: 1, 4, 6, 7, 12
Reference
Cheat sheets to keep open next to the editor.
Cheat sheet · soonString methods
Cheat sheet · soonList and dictionary methods
Cheat sheet · soonPaths and files:
pathlibCheat sheet · soonPython errors: the message and what it means