Chapters
Python114 chapters

ReferenceString methods

str.find()

The index of the first match, or -1 when there is none.

Signature

text.find(sub, start=0, end=len(text))

Parameters

NameMeans
subwhat to look for
startwhere to begin
endwhere to stop

Returns

An int, or -1.

Example

Python
line = "one,two,one"
print(line.find("two"))
print(line.find("three"))
print(line.rfind("one"))

Output

4
-1
8

See also