Anything that has __iter__() can return an iterator.
You can create an iterator like this:
>>> l = ['a', 'b', 'c', 'd'] >>> l_iterator = l.__iter__() # l.__iter__() returns an iterator. >>> for ch in l_iterator: ... print(ch) ... a b c d
>>> type(l_iterator) <class 'list_iterator'>The for loop calls next(iterable, iterator, generator). I think. I don't know for sure.
>>> l = ['a', 'b', 'c', 'd'] >>> l_iterator = l.__iter__() >>> next(l_iterator) 'a' >>> next(l_iterator) 'b' >>> next(l_iterator) 'c'And so on...
You can create an iterator like this:
my_iterator = iter(l)Then:
>>> for obj in my_iterator: ... repr(obj) ... "'a'" "'b'" "'c'" "'d'"