A class with __iter__() method or __getitem__() method is iterable. The __iter__() method returns an iterator. A iterator object has a next() method (or __next__() method in python 3.0).
class Iterator(object): def next(self): pass class Iterable(object): def __iter__(self): return Iterator()
see also
- Build a Basic Python Iterator
- What makes something iterable in python
- Understanding Python's iterator, iterable, and iteration protocols — what exactly are they?
No comments:
Post a Comment