In Python, a generator is a special type of iterator that allows you to iterate over a sequence of values without creating the entire sequence in memory at once. While a regular function uses return to send back a value and terminate, a generator function uses the yield keyword.
The yield Keyword
When a generator function calls yield, it pauses its execution and 'yields' a value to the caller. The function's state (including local variables) is saved, allowing it to resume exactly where it left off the next time it is called.