Overview
Python generators are a type of iterator in Python, with the important caviat that you can only iterate over them once.
They are created by writing a function what uses the keyword yield
rather than return
.
Type Annotations
Generators can be annotated with the Generator
type that is defined in the typing
module:
Code Examples
The following code example chunks up a list: