]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106318: Add example for str.index() (#137023)
authorAdorilson Bezerra <adorilson@gmail.com>
Tue, 6 Jan 2026 21:42:11 +0000 (21:42 +0000)
committerGitHub <noreply@github.com>
Tue, 6 Jan 2026 21:42:11 +0000 (23:42 +0200)
Doc/library/stdtypes.rst

index d77d731002019526be4734535ee59b8d4a673e81..5d64af43b6982814e7a26cf9be73e7ae07e2b9e3 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()