How to use the string find() method?

String.find() method returns the index of a substring in a string and using the find() function is very easy. You just need to call the find function with the object string and pass the substring as a parameter.

Let’s understand it better with an example:

Python3




string = " hello world is the first code of every programmer"
print(string.find("first"))


Output

20

Python String find() method

Python String find() method returns the lowest index or first occurrence of the substring if it is found in a given string.

Example

Python3




# initializing a string
word = 'find me if you can'
# using string find() method
print(word.find('me'))


Output

5

Similar Reads

Python String find() Method Syntax

...

What is the String find() Method?

str_obj.find(sub, start, end)...

How to use the string find() method?

String find() is an in-built function in Python that is used to find the index of a substring within a given string....

More Examples on String find() Method

String.find() method returns the index of a substring in a string and using the find() function is very easy. You just need to call the find function with the object string and pass the substring as a parameter....

Contact Us