Iteration Classes

itertools.islice()

Lazily select nonnegative positions, either islice(iterable, stop) or islice(iterable, start, stop[, step]). Step must be positive; negative slicing is not supported.

Formal Syntax & Structure

python syntaxpython
itertools.islice(iterable, stop) or itertools.islice(iterable, start, stop[, step])

Parameters & Attributes

NameTypeDescription
iterableiterableSource values.
startint or NoneOptional nonnegative starting position; omitted in the two-argument form.
stopint or NoneExclusive stop or None; required positional bound.
stepint or NonePositive step; None means one.

Return Value

iterator

The iterator result described above.

Working Example

Example Snippetpython
import itertoolsprint(list(itertools.islice(range(10),2,8,2)))
Python Reference