String Methods

str.rfind()

Locate the last occurrence of a substring entirely within the requested bounds. Return an absolute code-point offset in the original string, not an offset from start. Return -1 for a missing match; use in for a Boolean membership test and never use the result as a truth test. Empty substrings match boundaries, but a start beyond the original length does not match. The original string is unchanged.

Formal Syntax & Structure

python syntaxpython
text.rfind(sub[, start[, end]])

Parameters & Attributes

NameTypeDescription
substrSubstring to locate or count.
startint | NoneOptional inclusive start bound; negative values are relative to the end.
endint | NoneOptional exclusive end bound; defaults to the end.

Return Value

int

Absolute matching index, or -1 if absent.

Working Example

Example Snippetpython
path = "item/item"print(path.rfind("item"))print(path.rfind("item", 1))print(path.rfind("missing"))
Python Reference