Function Details: rindex

Description

Returns the highest index in the string where substring sub is found.

Extended Description

rindex is a Python string method that returns position of last occurrence of substring. Similar to rfind but raises ValueError when substring not found, offering stricter validation. Works with index for bidirectional search. Takes optional start and end parameters for search range. Partners with split and rpartition for text parsing. Used when substring must exist and searching from right is needed. Essential for validation and strict text processing from string's end.


Read More about rindex 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.


Return Type


int

Output

Explanation

This example demonstrates the basic usage of rindex(). It finds the last occurrence of 'hello'.