Academy
Python
10 pages · about 53 min of reading
- 01List Comprehensions in PythonHow a comprehension differs from a for-loop under the hood, when it trades readability for cleverness, and how the dict and set forms follow the same rule.
- 02Decorators in PythonWhat @decorator actually rewrites, why forgetting functools.wraps breaks introspection, and how a decorator that takes arguments needs a third level of nesting.
- 03Generators and Iterators in PythonThe iterator protocol every for-loop relies on, what yield actually suspends, and why a generator can process a file too large to fit in memory.
- 04Args and kwargs in PythonHow the star and double-star collectors turn extra positional and keyword arguments into a tuple and a dict, and where positional-only and keyword-only parameters fit.
- 05Mutable Default ArgumentsWhy a default value written as a list or dict is created once, shared across every call, and the None-then-create idiom that every codebase uses to avoid it.
- 06Context Managers in PythonWhat with is really calling, why __exit__ runs even when the block raises, and how @contextmanager turns a generator into one without writing a class.
- 07Exceptions and Error Handling in PythonWhat each clause of try/except/else/finally actually guarantees, how raise from chains a new exception to its cause, and why a bare except is almost always wrong.
- 08OOP and Dunder Methods in PythonHow __init__, __repr__ and __eq__ hook a class into built-in operators, why super() matters in a diamond hierarchy, and when composition beats inheritance.
- 09The GIL and Concurrency in PythonWhy threading does not speed up CPU-bound Python code, what the GIL actually serialises, and when to reach for multiprocessing or asyncio instead.
- 10Slicing and Mutability in PythonHow start:stop:step slicing works on any sequence, why a slice always copies while an index into a list of lists does not, and where is diverges from ==.