3 ms·
More generally, people write: for item in sequence: which is somewhat general (sequences include lists, dicts, strings, tuples, generators, text files and mor
by vram22 11y ago
More generally, people write:
for item in sequence:
which is somewhat general (sequences include lists, dicts, strings, tuples, generators, text files and more [2]), and it covers a wide range [1] of use cases.
[1] Pun not intended.
[2] Basically, any iterable. This include custom iterables you can define, which can then be iterated over using the same standard for loop. A unifying feature of the language:
"The use of iterators pervades and unifies Python."
https://docs.python.org/2/tutorial/classes.html#iterators https://docs.python.org/2/tutorial/classes.html#iterators