Language Syntax

Slicing — Python syntax

Create a slice key for the receiver; built-in sequences interpret omitted bounds and negative steps and exclude the stop index. The receiver determines the result type and whether data is copied.

Formal Syntax & Structure

python syntaxpython
object[start:stop:step]

Parameters & Attributes

NameTypeDescription
startexpressionFirst bound; omitted means receiver-defined default.
stopexpressionExclusive bound for built-in sequences.
stepexpressionStride; omitted means default.

Return Value

object

Value obtained by evaluating this expression; see description for context and constraints.

Working Example

Example Snippetpython
items='ABCDE'print((items[1:4:2],items[::-1]))
Python Reference