]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-106318: Add example for str.index() (GH-137023) (#143502)
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 1e9efbb97cff523bbd7eddd9dc03c097735872df..492282dc7b7ceab9882ffe564fc02ef023840daf 100644 (file)
@@ -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 "<python-input-0>", line 1, in <module>
+          'spam, spam, spam'.index('eggs')
+          ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
+      ValueError: substring not found
+
+   See also :meth:`rindex`.
 
 
 .. method:: str.isalnum()