For iterable to be used in foreach it must implement __iter__.
iterable.__iter__ will return an iterator, which must implement __next__.
Iterators:
Probably will be a part of built-in types (e.g. IteratorType, Iterator)
Will not be copied in foreach, it will conform to standard copying rules though.
Example:
For
iterable
to be used inforeach
it must implement__iter__
.iterable.__iter__
will return an iterator, which must implement__next__
.Iterators: Probably will be a part of built-in types (e.g.
IteratorType
,Iterator
) Will not be copied inforeach
, it will conform to standard copying rules though.