]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-106318: Add examples for str.rindex() method (GH-143887) (#144422)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 3 Feb 2026 13:36:32 +0000 (14:36 +0100)
committerGitHub <noreply@github.com>
Tue, 3 Feb 2026 13:36:32 +0000 (14:36 +0100)
gh-106318: Add examples for str.rindex() method (GH-143887)
(cherry picked from commit 45d00a0791a53f07c0050b985c936281ed825d9b)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Doc/library/stdtypes.rst

index ca7313ef73308f71afe410617e3009ae5eddf0fa..86a84faca97675fb63e21e9be23b5bf73240bb61 100644 (file)
@@ -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 "<python-input-0>", line 1, in <module>
@@ -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 "<stdin-0>", line 1, in <module>
+          'spam, spam, spam'.rindex('eggs')
+          ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
+      ValueError: substring not found
+
+   See also :meth:`index` and :meth:`find`.
 
 
 .. method:: str.rjust(width, fillchar=' ', /)