3 ms·
For the first approximation, you can simply explain it as part of the for-statement syntax. When you get to lists and iterating over them, this simple approach
by int_19h 5y ago
For the first approximation, you can simply explain it as part of the for-statement syntax. When you get to lists and iterating over them, this simple approach breaks, but by then you can redefine it as a kind of list.
Once you have explained iterators - and I don't mean the nitty gritty of __iter__(), next() etc, but rather the high-level notion of a function that yields multiple values to the caller, the true meaning of range() is easily explained in those terms.