Python Tutorials
Python from your first script to the things you will actually reach for at work — data types and strings, lists, dicts and sets, functions, comprehensions and generators, classes and dataclasses, exceptions, files, modules and async. Written against Python 3.12, kept short on purpose, and every code sample is executed before it ships.
- Python – Code SnippetsThe short answers you keep looking up — read a file into a list, sort a dict by value, flatten a nested list, count occurrences, chunk a list, merge dicts, retry a call, time a block. Copy, paste, move on.
- Python – Best PracticesThe conventions that make Python read like Python — PEP 8 and the formatter that enforces it, naming, EAFP over LBYL, comprehensions over loops over map, and the handful of habits that separate working code from code someone else can maintain.
- Python – DebuggingReading a traceback properly — it is the answer, not the noise — then `breakpoint()` and the handful of pdb commands worth knowing, logging instead of print, and the half-dozen error messages that mean something specific.
- Python – TestingWriting tests with pytest — plain asserts, arranging and asserting, fixtures, parametrising instead of copy-pasting, and testing that something raises. What unittest looks like for when you meet it, and what is worth testing at all.
- Python – Async & Awaitasync and await, and the one question that decides whether they help you at all: is the work waiting or computing. Coroutines, `asyncio.run`, running things at the same time with `gather`, and the blocking call that quietly ruins it.
- Python – Modules & PackagesSplitting code across files. What import really does, the search path, packages and `__init__.py`, the `if __name__ == "__main__"` guard, and why a circular import is a design problem rather than a syntax one.
- Python – User Input`input()` always hands you a string, which is where most beginner bugs start. Validating and converting it, looping until the answer is usable, hidden input for passwords, and `argparse` when the input is command-line arguments instead.
- Python – File (read/write)Reading and writing files with `with open(...)`, why the context manager is not optional, reading a large file a line at a time, `pathlib` instead of string paths, and the CSV and JSON modules you will reach for straight afterwards.
- Python – Exception Handlingtry, except, else and finally, catching the exception you meant rather than all of them, raising your own, chaining with `raise ... from`, and why a bare `except:` is the line that hides the bug you are looking for.
- Python – Dataclasses & Type Hints`@dataclass` writes the constructor, the repr and the equality you were about to write by hand. Plus type hints: what they do and do not do at runtime, the syntax worth knowing, and what a checker like mypy adds.
- Python – OOPInheritance, composition and polymorphism in a language with duck typing, where an interface is a set of methods rather than a declaration. `super()`, properties, abstract base classes, and when to prefer composition.
- Python – ClassWriting a class: `__init__`, what `self` actually is, instance versus class attributes, methods, and `__repr__` — the dunder that pays for itself the first time you print a list of your objects.
- Python – DecoratorsDecorators, built up from the one fact that makes them possible: functions are objects. Writing one, passing arguments through it, why `functools.wraps` is not optional, and the built-in decorators you already use.
- Python – Generators & IteratorsWhat the for loop is really doing, and how `yield` lets you produce a sequence without building it. Generator expressions, laziness and why it matters on a large file, and the one rule about consuming a generator twice.
- Python – Lambda FunctionsThe one-expression anonymous function. Where it belongs — a sort key, a small callback — where it does not, and why `sorted(xs, key=lambda p: p.name)` is the example that justifies the whole feature.
- Python – FunctionsDefining and calling functions, positional and keyword arguments, defaults, *args and **kwargs, returning values, docstrings, and the mutable-default-argument bug that is still the most common Python gotcha there is.
- Python – Dictionaries & SetsThe dict, which is the data structure Python is built on, and the set, which answers membership and de-duplication in one line. get and setdefault, iteration, dict and set comprehensions, and what makes a key hashable.
- Python – TuplesTuples and why an immutable sequence earns its place next to the list. Unpacking, returning more than one value, the starred target, named tuples, and the one-element tuple that catches everybody.
- Python – Lists & List ComprehensionsLists, the operations you actually use on them, sorting with a key, and list comprehensions — what they replace, when they are clearer than a loop, and the point past which they stop being readable.
- Python – Iteration (for / while loops)The for loop that walks a sequence rather than an index, when a while loop is the right shape, range, enumerate and zip, break and continue, and the loop-else clause almost nobody knows is there.
- Python – Conditional Statementsif, elif and else, what Python considers falsy and why that surprises people, the conditional expression, chained comparisons, and when `match` is genuinely clearer than a chain of elifs.
- Python – f-strings and FormattingFormatting text the modern way. f-strings, the format spec that lines up currency and columns, `=` for debugging, what changed in 3.12, and the two older styles you will still meet in real code and should not write.
- Python – String MethodsThe string methods worth memorising — strip, split, join, replace, startswith, and the case pair — plus slicing, why strings are immutable, and why building one in a loop with `+=` is the wrong tool.
- Python – Data TypesThe types you will use every day — int, float, str, bool, None — plus what a variable really is in Python, why `is` and `==` are not the same question, and the integer division and float rounding traps that bite everyone once.
- Python – IntroductionWhat Python actually is — a language and an interpreter, which is two things people use one word for. Why indentation is syntax rather than style, what dynamic typing buys you and costs you, where Python is used in 2026, and how its releases work.
- Python – Get StartedStart here. Install Python, run your first script, and understand the difference between the REPL and a file. Which Python version this track uses and why, every major 3.x release and what each one added, virtual environments and pip, and the map of the other 25 posts with the order to read them in.