From 4fb6a31bce36c8e04c0bda63f13467fc594b4425 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Tue, 6 Jan 2026 21:42:11 +0000 Subject: [PATCH] gh-106318: Add example for str.index() (#137023) --- Doc/library/stdtypes.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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() -- 2.47.3