The slice object is used to slice the given sequences like string, bytes, tuple, list, range or any object which supports the sequence protocol ( which implements getitem() and len() method).

Python Slice Example

Python slice() is an inbuilt function that creates the slice object representing the set of indices specified by range(start, stop, step). The slice object is used to determine how to slice the sequence. You can specify where to start the slicing, and where to end.  You can also determine the step, which allows you to, e.g., slice only every other item.

Syntax

The syntax of the Python slice() function is the following.

slice(stop)
slice(start, stop, step)

#python #python slice

Python Slice: How to Use slice() Method in Python
27.05 GEEK