Skip to content

Python substring index get (find) | Example code

  • by

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')

print(res)

Output:

Python substring index get find

Using start and end Arguments

text = 'Python is programing or is fun'

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

print(res)

Output: 24

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

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

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

Leave a Reply

Your email address will not be published. Required fields are marked *