From: Adorilson Bezerra Date: Tue, 6 Jan 2026 21:42:11 +0000 (+0000) Subject: gh-106318: Add example for str.index() (#137023) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fb6a31bce36c8e04c0bda63f13467fc594b4425;p=thirdparty%2FPython%2Fcpython.git gh-106318: Add example for str.index() (#137023) --- diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index d77d73100201..5d64af43b698 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2045,7 +2045,18 @@ expression support in the :mod:`re` module). .. method:: str.index(sub[, start[, end]]) Like :meth:`~str.find`, but raise :exc:`ValueError` when the substring is - not found. + not found. For example: + + .. doctest:: + + >>> 'spam, spam, spam'.index('eggs') + Traceback (most recent call last): + File "", line 1, in + 'spam, spam, spam'.index('eggs') + ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^ + ValueError: substring not found + + See also :meth:`rindex`. .. method:: str.isalnum()