From 431ae0dabf3b5f951c1a563f9867a9077a7e03b7 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 4 Feb 2026 17:17:42 +0000 Subject: [PATCH] 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> --- Doc/library/stdtypes.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 86a84faca97675..cca4ed1abdf545 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, /)