Generators and yield
A generator function produces values one at a time and pauses between them, keeping all its local state. It is the easiest way to write an iterator an...
A complete core Python path: syntax, data types, operators, strings, control flow, collections, functions, exceptions, files, modules, the standard library, OOP, iterators, generators, decorators, internals, concurrency, regular expressions, testing, typing, performance, security, problem solving, projects, interview preparation and exams.
110 notes in 33 topics
A generator function produces values one at a time and pauses between them, keeping all its local state. It is the easiest way to write an iterator an...
Lazy means computing a value only when it is asked for. Python uses it throughout, and using it deliberately is what makes a program handle data large...
A decorator takes a function, wraps it in another function, and gives the wrapper the original name. The @ symbol is shorthand for exactly that.
Registries, access control, deprecation, rate limiting and instrumentation - the decorator shapes that appear in real codebases, and how to test them.
A context manager guarantees that setup and cleanup both happen, whatever occurs in between. with is how you use one, and two methods are all it takes...
A descriptor is an object that controls what happens when an attribute is read, written or deleted. property, methods, classmethod and staticmethod ar...
A dataclass generates __init__, __repr__ and __eq__ from field declarations. It removes the boilerplate from every class whose main job is holding dat...
Everything in Python is an object with a type, an identity and a value. Names are labels bound to objects, and almost every surprising behaviour follo...
Assignment shares, a shallow copy duplicates one level, and a deep copy duplicates everything. Choosing the wrong one is one of the most common source...
Python frees an object the moment nothing refers to it. A second collector exists solely to find reference cycles, which counting alone can never recl...
Compilation, the code object, the stack machine and the frame. A closer look at what the interpreter is actually doing while your program runs.