]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106318: Add examples for str.rindex() method (#143887)
authorAdorilson Bezerra <adorilson@gmail.com>
Tue, 3 Feb 2026 13:29:05 +0000 (13:29 +0000)
committerGitHub <noreply@github.com>
Tue, 3 Feb 2026 13:29:05 +0000 (13:29 +0000)
Co-authored-by: Victor Stinner <vstinner@python.org>
Doc/library/stdtypes.rst

index ce0d7cbb2e42768fce82bde2abdeec3358672936..99479091cd5bd21c93af3c4657c195d16ed9cd26 100644 (file)
@@ -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 "<python-input-0>", line 1, in <module>
@@ -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 "<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=' ', /)