String Methods
rindex()
Find the last position of some text and raise an error if it is missing.
str.rindex(sub, start=0, end=len(str))
Find the last position of some text and raise an error if it is missing.
Arguments
Parameters
| Name | Description |
|---|---|
| sub | The text to look for. |
| start | Optional starting position. |
| end | Optional position where the search stops. |
Result
Returns
The highest index where the text occurs.
Run it
Try it
Run it and change it
text = "banana"
print(text.rindex("na")) Output
Press Run to see what it prints.Worth knowing
rindex()raisesValueErrorif the text is missing, whilerfind()returns-1.