The rindex() method returns the highest index of the substring inside the string if substring
is found. Otherwise it raises an exception.
str.find(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 indxes is not included in our search.
Returns the highest index of the substring inside the string if substring is found. Otherwise it raises an exception.
input: text = 'geeks for geeks' result = text.rindex('geeks') output: 10 input: text = 'geeks for geeks' result = text.rindex('ge') output: 10
Errors and Exceptions:
ValueError : This error is raised when the argument string is not found in the target string.
Substring 'geeks': 10
Traceback (most recent call last): File "/home/dadc555d90806cae90a29998ea5d6266.py", line 6, in result = text.rindex('pawan') ValueError: substring not found
- Python | Pandas Series.str.rindex()
- 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 | Merge Tuple String List values to String
- Python | Sorting string using order defined by another string
- Python | Check if string ends with any string in given list
- Python | Check if a given string is binary string or not
- String slicing in Python to rotate a string
- Python String
- Python | Add one string to another
- Python String | max()
- Python String | min()
- Python | String translate()
- Python String | ascii_letters
- Python | Intersection of two String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.