How to get a substring of a string in Python

In this article, we will see how to get a substring of a string in Python.

Python strings are sequences of individual characters. Python calls the concept “slicing” to get substring of Python string. Indexing starts from 0 to n-1(length of string -1).

Python Slice Notation:

a[start:stop] # items start through stop-1 a[start:] # items start through the rest of the array a[:stop] # items from the beginning through stop-1 a[:] # a copy of the whole array

There is also the step value, which can be used with any of the above:

a[start:stop:step] # start through not past stop, by step

Continue reading How to get a substring of a string in Python