rfind() method returns the highest index of the substring if found in given string. If not found then it returns -1.
str.rfind(sub, start, end)
sub : It’s the substring which needs to be searched in the given string.
start : Starting position where sub is needs to be checked within the string.
end : Ending position where suffix is needs to be checked within the string.
NOTE : If start and end indexes are not provided then, by default it takes 0 and length-1 as starting and ending indexes where ending indexes is not included in our search.
Return : Returns the highest index of the substring if it is found in given string; if not found, then it returns -1.
ValueError : This error is raised in the case when the argument string is not found in the target string.
Substring 'geeks' found at index : 10 Substring 'for' found at index : 6 Substring 'ate' found at index : 13
10 10 -1 6
Practical Application :
Useful in string checking. To check if given substring is present in some string or not.
Doesn't contains given substring
- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- numpy string operations | rfind() function
- Python | Pandas Series.str.rfind()
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Check if given string can be formed by concatenating string elements of list
- Python - Remove front K characters from each string in String List
- Python | Merge Tuple String List values to String
- Python | Sorting string using order defined by another string
- Python - Length of shortest string in string list
- Python | Check if string ends with any string in given list
- Python | Delimited String List to String Matrix
- Python | Sort each String in String list
- Python | Check if a given string is binary string or not
- Python - Remove String from String List
- String slicing in Python to rotate a string
- String Alignment in Python f-string
- String to Int and Int to String in Python
- Python String | max()
- Python String | min()
- Python | Add one string to another
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.