Generator
Generator — A generator is a function that returns an iterator using the `yield` keyword, producing values lazily one at a time. Generators are memory-efficient because they produce values on-demand rather than storing the entire sequence in memory. They are defined like regular functions but use `yield` instead of `return`. Generator expressions (like list comprehensions with parentheses) provide a concise way to create generators. Related terms: Decorator, Context Manager, GIL (Global Interpreter Lock), Duck Typing, List Comprehension, Mutable vs Immutable. Understanding generator makes the rest of the Python documentation noticeably easier to follow, because the concept recurs across function references, guides, snippets, and error messages you will meet in real projects. Look up more definitions in the Python glossary, or put the concept into practice with an example from the Python playground.