all Python 3Strings (str)function
str.rfind
search
Return the highest index of the substring, or -1 if not found (search from the right).
Syntax
s.rfind(sub[, start[, end]])
Only the scan direction is reversed: the returned index is still counted from the start of the string, never negative, and start/end still delimit a slice in the usual order. To split on the last separator, rpartition or rsplit with maxsplit=1 is usually cleaner, since they hand you the pieces without index arithmetic. The strict twin that raises ValueError instead of returning -1 is rindex.
Examples
print('hello'.rfind('l')) # → 3
print('hello'.rfind('z')) # → -1
print('abcabc'.rfind('a')) # → 3
See also
Open in the full glossarydocs.python.orgReport an inaccuracy