Python slice() function
Published February 17, 2022The slice() function returns a part of an iterable as an object of the slice class depending on the provided range. It may be used with range objects, list, set, tuple, bytes, strings, and customised class objects that support the len() and getitem() sequence functions.
The Syntax of the slice()
The slice() method is written as follows:
slice(stop) |
The slice() function supports three parameters:
start: The index at which the object slicing begins.
Stop: The index at which the object slicing comes to an end.
Step: An optional input controls the slicing increment among each index.
Let's take a look at the example of the slice().
Example
my_string = 'ILovePython' |
Output
String slicing |
Article Contributed By :
|
|
|
|
244 Views |