Menu Close

Python String find() Method

python string find() method

In this article, we are going to learn about the python string find() method. string find function is a string function that is only used with string to find the first occurrence of a specified value.
In the previous tutorial, we have seen the python string expandtabs() method.

Python String find() Method:

The Python string find() method is a string method which only used with the string data type.
The find() method which is used to find the substring in the whole string and return the number of index of the first match otherwise return -1 for not match.


The syntax of Python string find() method is:

string.find(substring, start, stop)


The python string find function accept three parameters:-

substring – Required
start – ( Optional ) Position where the search start.
stop – ( Optional ) Position where the search end.

Let’s see an example for using Python find() string method.

Python String find() Method Example:

Here we will take various example to understand string find() method.

Example 1:

str = "Welcome to the programming funda."
print("Old string:- ", str)

str2 = str.find('the')


Old string:-  Welcome to the programming funda.

Example 2:

str = "Programming Funda"
print("Old string:- ", str)

str2 = str.find('Fu', 12, 17)


Old string:-  Programming Funda

Example 3:

str = "Python"
print("Old string:- ", str)

str2 = str.find('Pro')

Output will be:- -1


In this tutorial, you have learned about Python string find() method to find any substring from string. This is the best method, If you want to find any substring from string in specific range.

I hope this string method tutorial will help you. If you like this article, please share with your friends who want to learn Python program from scratch to advanced.

For More Information:- Click Here

Python String expandtabs() Method
Python String format() Method

Related Posts