Javatpoint Logo
Javatpoint Logo

Python String find() Method

Python find() method finds substring in the whole string and returns index of the first match. It returns -1 if substring does not match.

Signature

Parameters

  • sub : substring
  • start : start index a range
  • end : last index of the range

Return Type

If found it returns index of the substring, otherwise -1.

Let's see some examples to understand the find() method.

Python String find() Method Example 1

An example of simple find method which takes only single parameter (a substring).

Output:

11

Python String find() Method Example 2

It returns -1 if not found any match, see the example.

Output:

-1

Python String find() Method Example 3

Let's specify other parameters too and makes search more customize.

Output:

8
-1

Python String find() Method Example 4

Output:

8
24

Next TopicPython Strings




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA