Skip to content
Built-in Functions

slice()

Create a slice object for selecting part of a sequence.

slice(start, stop=None, step=None)

slice() stores the start, stop, and step used in slicing.

You can use the resulting object inside square brackets.

Parameters

NameDescription
startWhere the slice starts.
stopWhere the slice stops before.
stepOptional spacing between selected items.

Returns

A slice object.

Try it

Run it and change it
word = "Python"
middle = slice(1, 5)
print(word[middle])

Related entries