TLDR Web Dev · ARTICLES & TUTORIALS

PYTHON: RANGE IS NOT AN ITERATOR

treyhunner.com8 min read

Summary from the TLDR Web Dev newsletter

Iterators and range objects are different in Python. While both are considered "lazy iterables" as they compute values on demand, they differ in their underlying mechanisms. Iterators are stateful, meaning once an item is consumed, it's gone. Range objects are not iterators - they are "lazy sequences" that can be looped over repeatedly without exhausting their values.