From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 4 Feb 2026 17:24:35 +0000 (+0100) Subject: [3.13] gh-106318: Add examples for `str.startswith()` method (GH-144369) (#144480) X-Git-Tag: v3.13.13~216 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=65acd016939d73e8d0530a9b933c0982de252844;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-106318: Add examples for `str.startswith()` method (GH-144369) (#144480) gh-106318: Add examples for `str.startswith()` method (GH-144369) (cherry picked from commit 1b6d737ee0205521333cf5fe6ca6df2d3a6d4ec2) Co-authored-by: Adorilson Bezerra Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 86a84faca976..cca4ed1abdf5 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2510,6 +2510,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, /)