Search This Blog

python: iterables and iterators

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

No comments:

Post a Comment