culTest

    One of the 50 questions in this topic

    How much do you know about Python?

    What is an iterator in Python?

    Answers

    Un bucle for o while
    An object that implements the __iter__() and __next__() methodsCorrect
    A function that counts iterations
    An index on a list or tuple

    An iterator is an object that implements the iterator protocol with the methods __iter__() (returns the iterator) and __next__() (returns the next element or throws StopIteration). Iterators allow you to efficiently traverse collections of data without loading all the elements into memory. They are the basis of for loops, comprehensions and functions like map() or filter(). All iterators are iterables, but not all iterables are iterators.