Python String find() method

The string.find() method in Python finds the first occurrence of the specified value and returns the lowest index in the string if the substring sub is found else it returns -1 if the sub is not found.

Syntax

Parameter

sub: This parameter represents the substring to be searched in the string str.

start( Optional): This parameter signifies the substring from where the search is to start and its default value is 0.

end: This parameter signifies the substring from where to end the search and its default value is the end of the string.

Return

This method returns the lowest index in the string if the substring sub is found else it returns -1 if the sub is not found.

Example 1

Output

Example 2

Output

Pin It on Pinterest

Share This