Skip to content

Commit e3c43bb

Browse files
committed
gh-106318: Add example for str.index()
1 parent ed4cc6f commit e3c43bb

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
@@ -1970,7 +1970,18 @@ expression support in the :mod:`re` module).
19701970
.. method:: str.index(sub[, start[, end]])
19711971

19721972
Like :meth:`~str.find`, but raise :exc:`ValueError` when the substring is
1973-
not found.
1973+
not found. For example:
1974+
1975+
.. doctest::
1976+
1977+
>>> 'spam, spam, spam'.index('eggs')
1978+
Traceback (most recent call last):
1979+
File "<python-input-0>", line 1, in <module>
1980+
'spam, spam, spam'.index('eggs')
1981+
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
1982+
ValueError: substring not found
1983+
1984+
See also :meth:`rindex`.
19741985

19751986

19761987
.. method:: str.isalnum()

0 commit comments

Comments
 (0)