]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106318: Improve str.removeprefix() and str.removesuffix() docs (#143580)
authorAdorilson Bezerra <adorilson@gmail.com>
Fri, 9 Jan 2026 15:22:50 +0000 (15:22 +0000)
committerGitHub <noreply@github.com>
Fri, 9 Jan 2026 15:22:50 +0000 (16:22 +0100)
Add doctest role and 'See also'.

Doc/library/stdtypes.rst

index e7c757405371c3f32ece632cb01b41cc6edd752d..3d347a59717bce1dccc0d43a5a288ce077ae0ad0 100644 (file)
@@ -2369,7 +2369,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'
@@ -2378,12 +2380,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'
@@ -2392,6 +2398,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)