find()

A string method that returns the index where a substring first appears, or -1 if it does not appear.

In more detail

s.find(sub, start) begins looking from index start, which lets you find later occurrences; rfind searches from the right. Check for -1 before using the result as an index, because -1 is a valid index meaning the last character.

Example

"Mississippi".find("ss")   # 2

Related terms

Taught in

References