Web Analytics

Python str.find() Method

String Method โ€ข Search

The find() method finds the first occurrence of the specified value. The find() method returns -1 if the value is not found.

The find() method is almost the same as the index() method, the only difference is that the index() method raises an exception if the value is not found.

Syntax

string.find(value, start, end)

Parameters

Parameter Description
value Required. The value to search for
start Optional. Where to start the search. Default is 0
end Optional. Where to end the search. Default is to the end of the string

Return Value

Integer. The index where it was found, or -1 if not found.

Example

Using the find() method:

Output
Click Run to execute your code

Related Functions