Why do we learn iterators and generators after arrays, lists, etc?
Iterators are a class that define methods for accessing and traversing (passing from one element to another) data and create instances that are "iterable". Generators are a subclass of iterators that create an iterable generator object by calling "yield" in a function. Lists and arrays are classes of containers that inherit, adapt and extend the Iterator methods.
"in Python, an iterator is an object which implements the iterator protocol, which consist of the methods __iter__() and __next__()"
--quoted from w3schools
Iterators are custom objects hence they represent a more advanced topic that involves OOP and the implementation of magic methods.
Generators are bringing in tools from functional programming (lazy sequences).
Arrays / lists are really the most basic data structures that can be found in all programming languages, and probably the easiest way to explain the usefulness of for/while loops to a beginner. I think that is enough reason to learn them first.
True. But they are also called and created in for loops. It seems to be something quite fundamental to how programming languages work. Perhaps it's just too abstract for introductory material where you do want to describe things that are easy for the learner to visualize/relate to.
Iterators are classes, while generators are functions.
Tibor Santa to clarify: both are "lazy". It is just the way they handle the state.
Iterators keep the state inside them as any other Object in OOP would. A call of __next__() changes the state.
Generators are stateful functions, or "lazy". They are indeed special, as they use the yield keyword. Yield creates a generator from a function. That way a functions execution is set on hold, once the value is returned and will continue once the generator is called again.
Think of it as an iterator, but wihout all the ugly OOP stuff.