Skip to the workspace
Pebellslearn by building

Python syntax & reference

Find the form you need, compare how it behaves, and open the complete explanation when you need more depth.

Python 3.10+ syntax; individual entries identify newer features. Browser exercises use the configured Python runner.

1 matching syntax entry

Iterable versus iterator

Learn in depth →

An iterable supplies an iterator. An iterator retains a position and produces values through next.

iterator = iter(iterable)
next(iterator, default)

Example

source = [10, 20]
a, b = iter(source), iter(source)
print(next(a), next(a), next(b))
print(next(a, "end"))

Result

10 20 10
end

Watch for: A consumed iterator is not automatically reset. Creating an iterator from a list can start an independent traversal.

Practise this topic →
Complete explanation index (91 lessons indexed)

Writing an Iterable by Hand

Technical sources and review date

Original Pebells examples. Reviewed 2026-10-28.

Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.