Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-106318: Add examples for str.rindex() method (GH-143887)
(cherry picked from commit 45d00a0)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
  • Loading branch information
2 people authored and miss-islington committed Feb 3, 2026
commit e20739aae9931cc0cd8f7381b5afa6aafedd1691
16 changes: 16 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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=' ', /)
Expand Down
Loading