]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-106318: Improve str.removeprefix() and str.removesuffix() docs (GH-143580...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 9 Jan 2026 15:29:04 +0000 (16:29 +0100)
committerGitHub <noreply@github.com>
Fri, 9 Jan 2026 15:29:04 +0000 (15:29 +0000)
gh-106318: Improve str.removeprefix() and str.removesuffix() docs (GH-143580)

Add doctest role and 'See also'.
(cherry picked from commit 6d6c7ed73786915d16f6ac3d8b6e6d67f404209f)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
Doc/library/stdtypes.rst

index 3efe8ede5cc83f8712a5ed5f9754793f3a9dcc1d..527717b8deb31c0d2ac2fd1381634d585170a8d7 100644 (file)
@@ -2231,7 +2231,9 @@ expression support in the :mod:`re` module).
 
    If the string starts with the *prefix* string, return
    ``string[len(prefix):]``. Otherwise, return a copy of the original
-   string::
+   string:
+
+   .. doctest::
 
       >>> 'TestHook'.removeprefix('Test')
       'Hook'
@@ -2240,12 +2242,16 @@ expression support in the :mod:`re` module).
 
    .. versionadded:: 3.9
 
+   See also :meth:`removesuffix` and :meth:`startswith`.
+
 
 .. method:: str.removesuffix(suffix, /)
 
    If the string ends with the *suffix* string and that *suffix* is not empty,
    return ``string[:-len(suffix)]``. Otherwise, return a copy of the
-   original string::
+   original string:
+
+   .. doctest::
 
       >>> 'MiscTests'.removesuffix('Tests')
       'Misc'
@@ -2254,6 +2260,8 @@ expression support in the :mod:`re` module).
 
    .. versionadded:: 3.9
 
+   See also :meth:`removeprefix` and :meth:`endswith`.
+
 
 .. method:: str.replace(old, new, /, count=-1)