Definition
The find() method finds the first occurrence of the specified value. It returns -1 if the value is not found.
The find() method is almost the same as the index() method, the only difference is that the index() method raises an exception if the value is not found.
Syntax
string.find(value, start, end)
Parameters
Parameter | Description |
---|---|
value | Required. The value to search for |
start | Optional. Where to start the search. Default is 0 |
end | Optional. Where to end the search. Default is to the end of the string |
Examples:
myStr = "Welcome to the Python tutorials."
result = myStr.find("Python")
print(result)
# finding the first occurrence of the letter "e"
result = myStr.find("e")
print(result)
# with positions to look for specified
result = myStr.find("e", 2, 12)
print(result)