4 ms·
What age were you introduced to Python? Explaining what range() does to elementary age children seems interesting.
by daniellarusso 5y ago
What age were you introduced to Python?
Explaining what range() does to elementary age children seems interesting.
- int_19h 5y agoFor 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.