From e20739aae9931cc0cd8f7381b5afa6aafedd1691 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Tue, 3 Feb 2026 13:29:05 +0000 Subject: [PATCH] gh-106318: Add examples for str.rindex() method (GH-143887) (cherry picked from commit 45d00a0791a53f07c0050b985c936281ed825d9b) Co-authored-by: Adorilson Bezerra Co-authored-by: Victor Stinner --- Doc/library/stdtypes.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ca7313ef73308f..86a84faca97675 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1922,6 +1922,8 @@ expression support in the :mod:`re` module). .. doctest:: + >>> 'spam, spam, spam'.index('spam') + 0 >>> 'spam, spam, spam'.index('eggs') Traceback (most recent call last): File "", line 1, in @@ -2305,6 +2307,20 @@ expression support in the :mod:`re` module). Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not found. + For example: + + .. doctest:: + + >>> 'spam, spam, spam'.rindex('spam') + 12 + >>> 'spam, spam, spam'.rindex('eggs') + Traceback (most recent call last): + File "", line 1, in + 'spam, spam, spam'.rindex('eggs') + ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^ + ValueError: substring not found + + See also :meth:`index` and :meth:`find`. .. method:: str.rjust(width, fillchar=' ', /)