Courses/Iterators, Generators & Decorators

Iterators, Generators & Decorators

Iterators

How for loops actually work under the hood.

Anything with __iter__ and __next__ is an iterator. iter() and next() give you manual control.

nums = iter([10, 20, 30])
print(next(nums))  # 10
print(next(nums))  # 20
main.py
Output
Press Run to execute.
Expected output
a
b
c

Sign in to track your progress across lessons.