]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-106318: Add example for str.index() (GH-137023) (#143501)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 6 Jan 2026 21:48:19 +0000 (22:48 +0100)
committerGitHub <noreply@github.com>
Tue, 6 Jan 2026 21:48:19 +0000 (21:48 +0000)
Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
Doc/library/stdtypes.rst

index 9f1bcc9240f0e6afdbdb2617162585a25fe429b9..c8cbf642ea6364c9e7922c8bc364c29f0dd267af 100644 (file)
@@ -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 "<python-input-0>", line 1, in <module>
+          'spam, spam, spam'.index('eggs')
+          ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
+      ValueError: substring not found
+
+   See also :meth:`rindex`.
 
 
 .. method:: str.isalnum()