From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 6 Jan 2026 21:48:19 +0000 (+0100) Subject: [3.13] gh-106318: Add example for str.index() (GH-137023) (#143501) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a8e97e17428710a7edb35862ce98dfdc2147da3;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-106318: Add example for str.index() (GH-137023) (#143501) Co-authored-by: Adorilson Bezerra --- diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 9f1bcc9240f0..c8cbf642ea63 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1907,7 +1907,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()