These are built-in functions of python, they are used for working with iterables.
Basically iter()
calls the __iter__()
method on the iris_loader
which returns an iterator. next()
then calls the __next__()
method on that iterator to get the first iteration. Running next()
again will get the second item of the iterator, etc.
This logic often happens ‘behind the scenes’, for example when running a for
loop. It calls the __iter__()
method on the iterable, and then calls __next__()
on the returned iterator until it reaches the end of the iterator. It then raises a stopIteration
and the loop stops.
Please see the documentation for further details and some nuances: https://docs.python.org/3/library/functions.html#iter