Name

.find()

Examples
pet = 'sea snail'
print(pet.find('a'))       # Prints the index of the 'a' in 'pet': 2.
print(pet.find('a', 3, 7)) # Prints the index of the second 'a' in 
                             # 'pet': 6.

print(pet.find("snail"))   # Prints 4.

print(pet.find("rock"))    # Prints -1.
Description Return the lowest index in the string where a substring is found. Optional arguments start and end specify a range to search in. If the substring is not found, returns -1.
Syntax
a.find(sub)
a.find(sub,start,end)
Parameters
subsubstring to search for
startstarting point in search range
endend point in search range
Related string
String Formatting
.find()
.strip()
.join()
.replace()

Updated on Tue Feb 27 14:07:12 2024.

If you see any errors or have comments, please let us know.