]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-106318: Add examples for `str.startswith()` method (GH-144369) (#144481)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 4 Feb 2026 17:23:55 +0000 (18:23 +0100)
committerGitHub <noreply@github.com>
Wed, 4 Feb 2026 17:23:55 +0000 (17:23 +0000)
gh-106318: Add examples for `str.startswith()` method (GH-144369)
(cherry picked from commit 1b6d737ee0205521333cf5fe6ca6df2d3a6d4ec2)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Doc/library/stdtypes.rst

index 7b983f25c46e60d6266cd410e1f183d67dd1ddae..23364b92ba39e9448a40f2f803bf69a1e234d519 100644 (file)
@@ -2751,6 +2751,19 @@ expression support in the :mod:`re` module).
    test string beginning at that position.  With optional *end*, stop comparing
    string at that position.
 
+   For example:
+
+   .. doctest::
+
+      >>> 'Python'.startswith('Py')
+      True
+      >>> 'a tuple of prefixes'.startswith(('at', 'a'))
+      True
+      >>> 'Python is amazing'.startswith('is', 7)
+      True
+
+   See also :meth:`endswith` and :meth:`removeprefix`.
+
 
 .. method:: str.strip(chars=None, /)