SyntaxStudy
Sign Up
Python Beginner 3 min read

Iterables vs Iterators

Iterables vs Iterators

An iterable is any object you can loop over (list, string, range). An iterator is an object that produces values one at a time with next().

Example
my_list = [1, 2, 3]          # iterable
it = iter(my_list)           # iterator
print(next(it))  # 1
print(next(it))  # 2
print(next(it))  # 3
Pro Tip

iter() converts an iterable to an iterator; next() fetches the next value.