Home >>Python String Methods >Python String index() Method
Python String index() Method returns index of first occurrence substring in a string and an error if there is no match found. This method is same as the find() method but raises an exception if sub is not found.
Syntax:string.index(value, start, end)
Parameter | Description |
---|---|
value | It is required the value search for |
start | It is Optional. The default value is 0. The value where to start the search |
end | It is Optional. The value where to end the search. Default value is to the end of the string |
indtxt = "hi, welcome to phptpoint."
z = indtxt.index("phptpoint")
print(z)
txt1 = "Hi, welcome to phptpoint."
a = txt1.index("e", 8, 13)
print(a)