CKTIS / Python
str.rfind
Finds the highest starting index of a matching substring.
Version: Python 3.14; repository image, production runtime not attested
Syntax
s.rfind(sub[, start[, end]])Finds the highest starting index of a matching substring.
Failure returns minus one, which is also a valid negative index if used to access a sequence.
Finds the last start position within the optional bounds. The character at end is excluded, but an empty match can start exactly at that boundary. The last an in bananas starts at three. The absent z gives -1, a valid last index only on a nonempty sequence.
assert "abc".rfind("", 1, 2) == 2 and "abc".rfind("c", 1, 2) == -1
Examples
print("bananas".rfind("an"))
print("bananas".rfind("z"))
Result
3 -1
Finds the last start position within the optional bounds. The character at end is excluded, but an empty match can start exactly at that boundary. The last an in bananas starts at three. The absent z gives -1, a valid last index only on a nonempty sequence.