Skip to content

Commit 0a8e97e

Browse files
[3.13] gh-106318: Add example for str.index() (GH-137023) (#143501)
Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
1 parent 8ca9005 commit 0a8e97e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Doc/library/stdtypes.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,18 @@ expression support in the :mod:`re` module).
19071907
.. method:: str.index(sub[, start[, end]])
19081908

19091909
Like :meth:`~str.find`, but raise :exc:`ValueError` when the substring is
1910-
not found.
1910+
not found. For example:
1911+
1912+
.. doctest::
1913+
1914+
>>> 'spam, spam, spam'.index('eggs')
1915+
Traceback (most recent call last):
1916+
File "<python-input-0>", line 1, in <module>
1917+
'spam, spam, spam'.index('eggs')
1918+
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
1919+
ValueError: substring not found
1920+
1921+
See also :meth:`rindex`.
19111922

19121923

19131924
.. method:: str.isalnum()

0 commit comments

Comments
 (0)