written 23 months ago by |
Solution:
Indexing operation:
The indexing syntax of a slice is a shorthand or a better substitute for the slice() as it’s easier to understand and execute.
Python index () method is the same as the find() method except it returns an error on failure.
This method returns the index of the first occurred substring and an error if there is no match found.
Indexing Syntax:
String[start : stop : step] So here, instead of creating a slice object first and then implementing it on the string, we directly use the indexing syntax that performs the same operation.
Output:
Slicing operation:
Python provides us with a method slice () that creates a ‘slice’ object that contains a set of ‘start’ & ‘stop’ indices and step values.
To be specific about the parameters, it is (start, stop, step).
slice (start, stop, step) Both slice() implementations return an object of the format slice(start, stop, end).
Output: