Iterators in Python are objects that implement both __iter__ and __next__ special methods. iter() is called internally to support:
forloop.- Tuple unpacking, example such as
x, y = IterableObject - Unpacking actual function parameters in function calls such as
*argsand**kwargs list,dict, &setcomprehensions such as[e for e in L]- Looping over text files line by line such as
for line in file: print(line) - Collection types construction such as
list(obj)ortuple(obj)