Python substring index get (find) | Example code

Use string index() to find the substring index value. This method returns the index of a substring inside the string (if found).

string.index(value, start, end) 

Get substring index value in Python

Simple example code finds substring index value if found and else it raises an exception. Using index() function With Substring argument Only.

text = 'Python is development'

res = text.index('is')



Python substring index get find

Using start and end Arguments

text = 'Python is programing or is fun'

res = text.index('is', 15, 30)


Output: 24

Do comment if you have any doubts and suggestions on this Python substring topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.