Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

str.find

Returns the lowest matching substring index within the search bounds.

Version: Python 3.14; repository image, production runtime not attested

Syntax

s.find(sub[, start[, end]])

Returns the lowest matching substring index within the search bounds.

A missing substring gives minus one; using that result directly as an index would select the last character.

Optional start and end bounds preserve original offsets. Starting at one skips the initial ca in cacao and finds the next ca at two. Using the failure value as an index on an empty string raises IndexError.

Examples

print("cacao".find("ca", 1))
print("cacao".find("z"))

Result

2
-1

Optional start and end bounds preserve original offsets. Starting at one skips the initial ca in cacao and finds the next ca at two. Using the failure value as an index on an empty string raises IndexError.

Sources