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

Lazy expressions and islice

Learn in depth →

A generator expression computes values as requested; islice limits consumption.

(expression for item in iterable)
itertools.islice(iterator, count)

Example

from itertools import islice
g = (n * n for n in range(100))
print(list(islice(g, 3)))
print(next(g))

Result

[0, 1, 4]
9

Watch for: Laziness does not make retained source data disappear. Some operations buffer or consume the entire input.

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

Generator Expressions

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.