Python – Create Slice Object – slice() Function with Examples

slice() function is used to find the constructor creates a slice object representing the set of indices specified by range(start, stop, step) in Python for the given input.

slice() function is a part of Python Built-in Functions.

Syntax of slice() Function

The syntax of slice() function in Python is:

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

 

Parameters of slice() Function in Python

x – Where x is any valid . This parameter is required.

 

Compatibility

slice() function is available and compatible with both Python 2.x and 3.x.

 

Return Value of slice() Function in Python

slice() function returns constructor creates a slice object representing the set of indices specified by range(start, stop, step) for the given input.

 

Python slice() Function Example 1

Example CODE

Output:

 

Python slice() Function Example 2

Example CODE

Output: