- `__slots__`
- A class attribute that replaces each instance's `__dict__` with a fixed set of named slots, cutting per-instance memory and blocking new attributes from being added later.
- Closure
- A function that remembers variables from the scope it was defined in, even after that scope has finished running. It is how a factory function can return a customized function.
- Context manager
- An object with `__enter__` and `__exit__` methods, used with `with` to guarantee cleanup — closing a file or releasing a lock — even if the block raises.
- Decorator
- A function that takes another function and returns a wrapped version of it, applied with `@name` above a definition. It adds behavior — logging, caching, retries — without changing the original function's code.
- Descriptor
- An object that customizes attribute access by defining `__get__`, `__set__`, or `__delete__`. Properties, methods, and `staticmethod` are all built from descriptors.
- Duck typing
- Python checks whether an object has the method or attribute you call, not what class it is. If it walks like a duck and quacks like a duck, your code treats it as one.
- Dunder method
- A method named with double underscores on both sides — `__init__`, `__len__`, `__eq__` — that Python calls automatically for a language feature like construction, `len()`, or `==`.
- Generator
- A function containing `yield` that produces values one at a time instead of building a full list in memory. Calling it returns an iterator that resumes from where it last paused.
- GIL (Global Interpreter Lock)
- A lock in CPython that lets only one thread run Python bytecode at a time. It is why CPU-bound work does not speed up with threads, but I/O-bound work still can — the lock releases during a blocking call.
- Idempotent
- An operation that produces the same result no matter how many times you run it. Setting an order's status to "shipped" is idempotent; incrementing a counter is not.
- LEGB
- The order Python searches for a name: Local, Enclosing, Global, Built-in. It stops at the first scope where the name exists.
- Metaclass
- The class of a class — usually `type`. It controls how a class itself is created, which is how libraries like Django inject behavior into every subclass.
- Monkey patching
- Replacing or adding an attribute on a class or module at runtime, outside its own source file. Common in tests as mocking, and risky in production code, since it changes behavior invisibly to anyone reading the original definition.
- MRO (Method Resolution Order)
- The order Python searches parent classes for a method or attribute in multiple inheritance, computed by the C3 linearization algorithm. `ClassName.__mro__` shows it directly.