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
| Name | Type | Description |
|---|---|---|
| iterable | iterable | Source values. |
| start | int or None | Optional nonnegative starting position; omitted in the two-argument form. |
| stop | int or None | Exclusive stop or None; required positional bound. |
| step | int or None | Positive 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)))