1. Strings can be indexed using string[index]

2. There is forward slicing as well as backward slicing. It starts from last element and index is -1.

3. Forward indexing starts from 0 to the positive range of number side and Negative indexing starts from -1 to the negative range of the number side.

Syntax: string[start_index:last_index]

*Note: last index is excluded internally and hence result is (last index - 1)

Forward Indexing:

0 1 2 3 4 5 6 7 8 9 10 11

h e l l o   p y t h  o  n


Backward Indexing:

-12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1

h   e   l   l  o     p  y  t  h  o  n


 Also, as it is zero based indexing, upper bound is excluded in the range. See the Note  and examples above.

If you want to slice from the beginning or till the end you can leave the start index or end index blank. If you leave both the index blank, it will simply print the whole string.

Below are some examples:- 


Hope this helps you. :)