]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106318: Add examples for `str.startswith()` method (#144369)
authorAdorilson Bezerra <adorilson@gmail.com>
Wed, 4 Feb 2026 17:17:42 +0000 (17:17 +0000)
committerGitHub <noreply@github.com>
Wed, 4 Feb 2026 17:17:42 +0000 (18:17 +0100)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Doc/library/stdtypes.rst

index 99479091cd5bd21c93af3c4657c195d16ed9cd26..0f20163e69509cd969675f51ff86884859f8b7de 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, /)