Find() method in Python String Module
find() method in string module helps to identify the word available in the string and gives its indexing position. If the word is not available it gives the output as -1.
Syntax:
str.find(sub[, start [, end] ]Parameters:
There are 3 parameters for find method.
- Sub: this is the substring which needs to be identified in the string.
- Start: this is used in the string from where the word is to be searched. This is an optional parameter
- End: this is used in the string where the word needs to be stopped searched.
Example-1: find() by using only sub
txt = "pebbles found in either side of the river."
x = txt.find("history")
print(x)
Output:
Example-2:
txt = "It is one of the largest financial centres."
x = txt.find("found")
print(x)
Output:
Example-3: find() using sub, start and end
txt = "Romans found Zurich in 15 BC."
x = txt.find("found",4,18)
print(x)
Output:
