Skip to content

Commit 4482064

Browse files
miss-islingtonadorilsonvstinner
authored
[3.13] gh-106318: Add examples for str.rindex() method (GH-143887) (#144422)
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>
1 parent 9d76689 commit 4482064

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
@@ -1922,6 +1922,8 @@ expression support in the :mod:`re` module).
19221922

19231923
.. doctest::
19241924

1925+
>>> 'spam, spam, spam'.index('spam')
1926+
0
19251927
>>> 'spam, spam, spam'.index('eggs')
19261928
Traceback (most recent call last):
19271929
File "<python-input-0>", line 1, in <module>
@@ -2305,6 +2307,20 @@ expression support in the :mod:`re` module).
23052307

23062308
Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not
23072309
found.
2310+
For example:
2311+
2312+
.. doctest::
2313+
2314+
>>> 'spam, spam, spam'.rindex('spam')
2315+
12
2316+
>>> 'spam, spam, spam'.rindex('eggs')
2317+
Traceback (most recent call last):
2318+
File "<stdin-0>", line 1, in <module>
2319+
'spam, spam, spam'.rindex('eggs')
2320+
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
2321+
ValueError: substring not found
2322+
2323+
See also :meth:`index` and :meth:`find`.
23082324

23092325

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

0 commit comments

Comments
 (0)