Function Details: slice

Description


Creates a slice object. Used for extended slicing (e.g. a[start:stop:step]).


Extended Description


The slice() function returns a slice object representing the set of indices specified by range(start, stop, step). It's used for extended slicing of sequences. A slice object can be used with any sequence type (string, list, tuple, etc.) to extract a subset of elements. The slice object itself is immutable.


Read More about slice from Python Documentation

Function Signature


slice(start: Optional[int], stop: Optional[int], step: Optional[int] = None) -> slice

Module: builtins

Class: slice

Parameters



Parameter List


  • start: Optional[int]
  • stop: Optional[int]
  • step: Optional[int]

Return


Returns a slice object.


Return Type


slice

Output

Explanation

This example shows how to create and use a slice object with different sequence types.