From zeroFree
Python
One topic per chapter, from installing Python to control flow, written to be read and then typed out on your own machine. Every chapter ends with a ten-question quiz that runs from easy to hard.
The six steps in every chapter
- 1Encounter
- 2Understand
- 3Worked
- 4Predict
- 5Apply
- 6Stretch
- 01Installing Python and running your first programInstall Python on Windows, confirm from the terminal that it actually works, and run your first Python file on your own machine.25 min10 questions
- 02The terminal, folders, and your first projectMove around your folders from the terminal, create a project folder, run files, and learn when Python's interactive shell is the right tool.25 min10 questions
- 03Seeing with print, explaining with commentsin-reviewHow print writes several things at once, how sep and end change that, and why comments exist — your first tool for seeing inside a running program.20 min10 questions
- 04Variables and types — how a program remembersin-reviewStoring values in variables, the rules for naming them, and the four basic types — int, float, str, bool — plus the error beginners hit most often.30 min10 questions
- 05Arithmetic — division, remainders, and the decimal trapin-reviewThe seven arithmetic operators, which one runs first, where integer division and remainders earn their keep, and why decimals sometimes answer strangely.30 min10 questions
- 06Working with text — indexing, slicing, and f-stringsin-reviewPulling pieces out of text, cleaning it, changing it, and building readable messages with f-strings — plus the rule that text cannot be modified in place.35 min10 questions
- 07Taking input from the person using your programin-reviewReading what someone types with input(), why it is always a str, and which errors show up when you convert it with int() and float().30 min10 questions
- 08True and False — learning to ask questionsin-reviewComparison operators, and / or / not, chained comparisons, and which values Python treats as false — the groundwork for writing conditions.30 min10 questions
- 09Making decisions — if, elif, elsein-reviewTaking different paths depending on a condition, why indentation carries meaning in Python, and the silent bug that comes from ordering conditions wrongly.35 min10 questions
- 10while loops — running while a condition holdsin-reviewRepeating the same work, how infinite loops happen and how to stop them, break and continue, and asking again until the input is valid.35 min10 questions
- 11for loops and range — running a known number of timesin-reviewWhen you know how many times, a for loop is the right choice. The three forms of range, why the end is excluded, and how to choose between for and while.35 min10 questions
- 12Lists — many values under one namein-reviewHolding as many values as you like under one name, reaching inside with an index and a slice, the methods that change a list, and the trap of two names ending up attached to the same one.30 min10 questions
- 13Sorting lists, and the methods that come with themin-reviewWhat separates sorted() from .sort(), the answers max/min/sum/count/index give, changing the rule with key=, and turning a list into readable text with join().30 min10 questions
- 14Tuples and unpackingin-reviewA list that cannot change, where that is exactly what you want, unpacking so you use names instead of indexes, swapping in one line, and the (5) versus (5,) trap.30 min10 questions
- 15Dictionaries — pairs of key and valuein-reviewStoring and fetching values by name, avoiding KeyError with .get(), adding and deleting keys, walking with .items(), and why a list cannot be a key.32 min10 questions
- 16Sets — a collection without duplicatesin-reviewRemoving duplicates, the four symbols that compare two collections, why {} is not an empty set, and what having no order actually means.28 min10 questions
- 17Nested data — a list of dictionariesin-reviewThe shape real data arrives in: dictionaries inside lists, lists inside dictionaries. Reaching in, grouping, and why copy() is not enough here.35 min10 questions
- 18Comprehensions — a loop on one linein-reviewList, dictionary and set comprehensions, the difference between a filtering if and a choosing if/else, and when a comprehension is the wrong choice.30 min10 questions
- 19Functions — one decision, one namein-reviewWriting functions with def, what separates return from print, handling edge cases with a guard at the top, and docstrings.35 min10 questions
- 20Function arguments — names, defaults, and starsin-reviewPassing arguments by name, default values and the rule about their order, *args and **kwargs, and unpacking a list or dictionary into a call.32 min10 questions
- 21Scope and mutable defaultsin-reviewWhere a name lives and who can see it, the difference between reading and writing an outer name, UnboundLocalError, and Python's most famous trap — the empty list as a default.34 min10 questions
- 22Modules and importsin-reviewUsing a file you wrote from another file, what an import actually does, why `if __name__ == "__main__"` is needed, the standard library, and hiding a module behind a file of your own.33 min10 questions
- 23Reading and writing filesin-reviewReading and writing with `with open`, what separates r/w/a/x, the newline at the end of every line, why `encoding` is always written, and pathlib for the small jobs.35 min10 questions
- 24Exceptions — handling what breaksin-reviewCatching one specific error with try/except, why `except Exception: pass` is nearly always wrong, `else` and `finally`, raising your own, and picking an error of the right size from the family.36 min10 questions
- 25JSON and CSVin-reviewReading and writing quoted tables with the csv module, why `newline=""` is needed, keeping structured data with json, and which types change in transit.34 min10 questions
- 26Classes — data and behaviour togetherin-review`class`, `__init__` and `self`, methods, a printable form with `__repr__`, equality with `__eq__`, class level against instance level, and when a class is not wanted.38 min10 questions
- 27Dataclasses and type hintsin-reviewWhat `@dataclass` writes for you, why `field(default_factory=...)` is needed, what `frozen=True` gives, type hints on functions, and what it means that hints do nothing at runtime and everything under a checker.36 min10 questions
- 28Testing with pytestin-reviewFrom `assert` to pytest, reading a failure report, `pytest.raises`, `parametrize`, `tmp_path` and fixtures — and which shape of code is easy to test.37 min10 questions
- 29Debugging and loggingin-reviewReading a traceback in the right order, logging instead of print, levels and `getLogger(__name__)`, keeping a caught error's full account with `log.exception`, and getting inside with `breakpoint()`.34 min10 questions