Andrew Breza

58%
Flag icon
Don’t Make the Iterable an Iterator for Itself A common cause of errors in building iterables and iterators is to confuse the two. To be clear: iterables have an __iter__ method that instantiates a new iterator every time. Iterators implement a __next__ method that returns individual items, and an __iter__ method that returns self. Therefore, iterators are also iterable, but iterables are not iterators.
Fluent Python: Clear, Concise, and Effective Programming
Rate this book
Clear rating
Open Preview