Home >>Python String Methods >Python String find() Method

Python String find() Method

Python String find() Method

Python string find() method is used to find the first occurrence of the required value. It returns -1 if the required value is not found.

Syntax:
string.find(value, start, end)

Parameter Values

Parameter Description
value This is a required parameter. It defines the value to search for.
start This is an optional parameter. It defines where to start the search.
end This is an optional parameter. It defines where to end the search.
Here is an example of Python find() method:

txt = "Welcome to PHPTPOINT."
x = txt.find("PHP")
print(x)

Output:
11
Example 2:

txt = "Welcome to PHPTPOINT"
x = txt.find("PHP",5,15)
print(x)

Output:
11
Example 3:

txt = "Welcome to PHPTPOINT"
x = txt.find("PHP",5,10)
print(x)

Output:
-1

No Sidebar ads