Python slice() Function
Description
slice()The function implements a slice object, mainly used for parameter passing in slice operation functions.
Syntax
slice syntax:
class slice(stop) class slice(start, stop[, step])
Parameter description:
- start -- start position
- stop -- end position
- step -- interval
Return Value
Returns a slice object.
Examples
The following examples demonstrate how to use slice:
>>>myslice = slice(5) # Set a slice to extract 5 elements
>>> myslice
slice(None, 5, None)
>>> arr = range(10)
>>> arr
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> arr[myslice] # Extract 5 elements
[0, 1, 2, 3, 4]
>>>
Python Built-in Functions