Although we can use the in
keyword to find if some word exists in a string, we sometimes instead require the index of the word of where it appears. Python has a .find()
method for the same. The .find()
method returns the index where the word is present in the string. It returns -1
if the word was not found.
If there are multiple occurrences of the word, we can provide a start index to .find()
. .find()
will then start searching for the word only from that index onwards.