Python Generators:
Generators are functions that can be paused and resumed.
Unlike lists, they produce items one at a time and only when asked.
So they are much more memory efficient.
Generator Functions:
A generator-function is defined like a normal function, but whenever it needs to generate a value, it does so with the yield keyword rather than return. If the body of a def contains yield, the function automatically becomes a generator function.
Example:
0 Comments