If you are using ipython (I can warmly recommend) you can type ?? before a command in order to see its docstring.

Doing so for string.rfind:

Docstring:

S.rfind(sub[, start[, end]]) -> int

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

Type: builtin_function_or_method

and for string.find:

Docstring:

S.find(sub[, start[, end]]) -> int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

Type: builtin_function_or_method

I took the liberty to highlight the important parts.

What it means is that both will return the same index if there is only one substring (i.e. 'k' in your case) found.

If you are still unsure about how str.rfind and str.find differ from each other, try the same thing with:

string = 'kooook'

Hope that helps and happy coding!

Answer from j-i-l on Stack Overflow
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › rfind.html
rfind — Python Reference (The Right Way) 0.1 documentation
>>> 'Py' in 'Python' True · >>> "ABAB".rfind("B") 3 >>> "ABAB".rfind("B", 0, 2) 1 >>> "ABAB".rfind("B", 2) 3 ·
🌐
W3Schools
w3schools.com › python › ref_string_rfind.asp
Python String rfind() Method
Python Examples Python Compiler ... Plan Python Interview Q&A Python Training ... The rfind() method finds the last occurrence of the specified value....
🌐
Programiz
programiz.com › python-programming › methods › string › rfind
Python String rfind()
If substring exists inside the string, it returns the highest index where substring is found. If substring doesn't exist inside the string, it returns -1. ... quote = 'Let it be, let it be, let it be' result = quote.rfind('let it') print("Substring 'let it':", result) result = quote.rfind('small') ...
🌐
Tutorialspoint
tutorialspoint.com › python › string_rfind.htm
Python String rfind() Method
The Python String rfind() method searches for the starting index of a last occurrence of a specified substring is found in an original string. Unlike the rindex() method, which raises an exception if the substring is not present, this method returns
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-rfind-method
Python String rfind() Method - GeeksforGeeks
February 21, 2025 - Python String rfind() method returns the rightmost index of the substring if found in the given string.
🌐
Codecademy
codecademy.com › docs › python › strings › .rfind()
Python | Strings | .rfind() | Codecademy
October 6, 2023 - .rfind() searches a given string for a substring starting from index 0, or alternatively, from the ith index to jth index (where i < j). The method returns the starting index of the last occurrence of the substring.
🌐
Learn By Example
learnbyexample.org › python-string-rfind-method
Python String rfind() Method - Learn By Example
April 20, 2020 - The rfind() method searches for the last occurrence of the specified substring and returns its index. If specified substring is not found, it returns -1.
Find elsewhere
🌐
Skytowner
skytowner.com › explore › python_string_rfind_method
Python String | rfind method with Examples
Python's str.rfind(~) method returns the index of the last occurrence of the specified substring in the source string. If the substring is not found, then -1 is returned. 1. sub | string · The substring to search for in the source string. 2. start | number | optional · The index of the source ...
🌐
Javatpoint
javatpoint.com › python-string-rfind-method
Python String | rfind() method with Examples - Javatpoint
rfind(str,beg=0,end=len(str)) rindex(str,beg=0,end=len(str)) rjust(width,[,fillchar]) rstrip() rsplit(sep=None, maxsplit = -1) split(str,num=string.count(str)) splitlines(num=string.count('\n')) startswith(str,beg=0,end=len(str)) swapcase() translate(table,deletechars = '') upper() zfill(width) rpartition() Python abs() Python all() Python bin() Python bool() Python bytes() Python callable() Python compile() Python exec() Python sum() Python any() Python ascii() Python bytearray() Python eval() Python float() Python format() Python frozenset() Python getattr() Python globals() Python hasattr()
🌐
Scaler
scaler.com › home › topics › rfind() in python
rfind() in Python | rfind() Function in Python - Scaler Topics
June 15, 2022 - The string rfind() method can also be used to check whether a substring is present in the given string or not. ... Substring in python.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.rfind.html
pandas.Series.str.rfind — pandas 3.0.4 documentation
Each of returned indexes corresponds to the position where the substring is fully contained between [start:end]. Return -1 on failure. Equivalent to standard str.rfind().
🌐
Homeip
owl.homeip.net › manuals › softdev › python › pythontut › www.tutorialspoint.com › python3 › string_rfind.htm
Python 3 String rfind() Method
The following example shows the usage of rfind() method. #!/usr/bin/python3 str1 = "this is really a string example....wow!!!" str2 = "is" print (str1.rfind(str2)) print (str1.rfind(str2, 0, 10)) print (str1.rfind(str2, 10, 0)) print (str1.find(str2)) print (str1.find(str2, 0, 10)) print (str1.find(str2, 10, 0))
🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › string.rfind.html
string.rfind() — Python Standard Library
string.rfind() View page source · string.rfind(s, sub[, start[, end]]) → int[source]¶ · Return the highest index in s where substring sub is found, such that sub is contained within s[start,end]. Optional arguments start and end are interpreted as in slice notation.
🌐
W3Schools
w3schools.com › python › ref_string_rindex.asp
Python String rindex() Method
Python Examples Python Compiler ... x = txt.rindex("casa") print(x) Try it Yourself » · The rindex() method finds the last occurrence of the specified value....
🌐
GUVI
guvi.in › hub › python-built-in-functions-tutorial › python-string-rfind
Understanding Python String rfind()
And in the second string, we have the substring Python 3 times, and the function rfind() returned the index of the right most occurence, which is the highest index.
🌐
TutorialKart
tutorialkart.com › python › python-string-rfind
Python String rfind() - Examples
April 3, 2023 - Python String.rfind() method returns the index of last occurrence of specified value in given string. The search for given value in this string happens from
🌐
datagy
datagy.io › home › python posts › python strings › python rfind: find index of last substring in string
Python rfind: Find Index of Last Substring in String • datagy
December 19, 2022 - Use the Python rfind method to find the last, or right-most, index of a substring in a Python string, including the difference to rindex.