From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 3 Feb 2026 13:36:27 +0000 (+0100) Subject: [3.14] gh-106318: Add examples for str.rindex() method (GH-143887) (#144421) X-Git-Tag: v3.14.3~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cc8fd6ac43ed014f449fb90e9dd4f6202a229f49;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-106318: Add examples for str.rindex() method (GH-143887) (#144421) 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 --- diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 67a0fa8afbd3..7b983f25c46e 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2163,6 +2163,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 @@ -2546,6 +2548,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=' ', /)