People mentioned string.find()
, string.index()
, and string.indexOf()
in the comments, and I summarize them here (according to the Python Documentation):
First of all there is not a string.indexOf()
method. The link posted by Deviljho shows this is a JavaScript function.
Second the string.find()
and string.index()
actually return the index of a substring. The only difference is how they handle the substring not found situation: string.find()
returns -1
while string.index()
raises an ValueError
.