What is 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.

It is a very easy and useful string function, that can help us find a given substring. It returns the index of the substring if it is found in the string, but if the substring is not present in the string it returns -1.

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