String Methods
rfind()
Find the last position of some text without raising an error when it is missing.
str.rfind(sub, start=0, end=len(str))
Find the last position of some text without raising an error when 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, or -1 if the text is not found.
Try it
Run it and change it
text = "banana"
print(text.rfind("na"))
Worth knowing
rfind()searches from the right for the last match;find()returns the first match.