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.
Parameters
| Name | Description |
|---|---|
| sub | The text to look for. |
| start | Optional starting position. |
| end | Optional position where the search stops. |
Returns
The highest index where the text occurs.
Try it
Run it and change it
text = "banana"
print(text.rindex("na"))
Worth knowing
rindex()raisesValueErrorif the text is missing, whilerfind()returns-1.