Python String find() Method Syntax

str_obj.find(sub, start, end)

Parameters

  • sub: Substring that needs to be searched in the given string. 
  • start (optional): Starting position where the substring needs to be checked within the string. 
  • end (optional): The end position is the index of the last value for the specified range. It is excluded while checking. 

Return

Returns the lowest index of the substring if it is found in a given string. If it’s not found then it returns -1.

Note:

  1. If the start and end indexes are not provided then by default it takes 0 and length-1 as starting and ending indexes where ending indexes are not included in our search.
  2. The find() method is similar to the index(). The only difference is find() returns -1 if the searched string is not found and index() throws an exception in this case.

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