Python slicing is used to return a range of characters from a string. This is done by specifying a start and an end index separated by a colon. The first character will have a 0 index value.
x="Educative"print(x[3:6])
This prints the string starting from the 3rd index until the 6th index.
The range will start from the first index up to the index specified by the user.
x="Educative"print(x[:6])
This prints the string from the start until the 6th index.
In this case, we'll specify a start index, and the end index will be left blank so that a string from the specified start to the end index is printed.
x="Educative"print(x[3:])
This prints the string from the 3rd to the last index.
This is used to begin the slicing from the end of a string.
x="Educative"print(x[-8:-4])
This prints the string from the -8 to -4 index values, which in this case are from d
until a
.