Learn Python

Finding a character in the string

We can use the find method to get the index of the first occurrence of a letter or substring in a string.

If the letter or substring is not found, find will return -1.

We can also define the range of indices where we want to search the word or character.

In the example below, we are trying to find the index of the character o between the indices 4 and -1.