Function Details: rfind
Description
Returns the highest index in the string where substring sub is found.
Extended Description
rfind is a Python string method that searches for the last occurrence of a substring and returns its index position. Similar to find but searches from right to left. Partners with rindex but returns -1 instead of raising error when substring not found. Works with optional start and end parameters for search range specification. Often used with string slicing and split operations. Useful in text parsing, particularly when processing file paths, URLs, or finding last occurrences of delimiters.
Read More about rfind from Python Documentation
Function Signature
Module: builtins
Class: str
Parameters
Parameter List
- sub: str
- start: int
- end: int
Return
Returns the highest index where the substring is found, or -1 if not found.
Return Type
int
Output
Explanation
This example demonstrates the basic usage of rfind(). It finds the last occurrence of 'hello'.