What is string slice? How is it used?
The substring obtained from within a string is called a string slice .
Following are the steps how it is used:
- Given a string str1, the slice operation str1[n:m] returns the part of the string str1 starting from index n (inclusive) and ending at m (exclusive).
- In other words, we can say that str1[n:m] returns all the characters starting from str1[n] till str1[m-1].
- The numbers of characters in the substring will always be equal to the difference of two indices m and n, i.e., (m-n).