Skip to content

Commit 45d00a0

Browse files
adorilsonvstinner
andauthored
gh-106318: Add examples for str.rindex() method (#143887)
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent bb917d8 commit 45d00a0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Doc/library/stdtypes.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,8 @@ expression support in the :mod:`re` module).
21632163

21642164
.. doctest::
21652165

2166+
>>> 'spam, spam, spam'.index('spam')
2167+
0
21662168
>>> 'spam, spam, spam'.index('eggs')
21672169
Traceback (most recent call last):
21682170
File "<python-input-0>", line 1, in <module>
@@ -2546,6 +2548,20 @@ expression support in the :mod:`re` module).
25462548

25472549
Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not
25482550
found.
2551+
For example:
2552+
2553+
.. doctest::
2554+
2555+
>>> 'spam, spam, spam'.rindex('spam')
2556+
12
2557+
>>> 'spam, spam, spam'.rindex('eggs')
2558+
Traceback (most recent call last):
2559+
File "<stdin-0>", line 1, in <module>
2560+
'spam, spam, spam'.rindex('eggs')
2561+
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
2562+
ValueError: substring not found
2563+
2564+
See also :meth:`index` and :meth:`find`.
25492565

25502566

25512567
.. method:: str.rjust(width, fillchar=' ', /)

0 commit comments

Comments
 (0)