]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106318: Improve str.rstrip() method doc (#143893)
authorAdorilson Bezerra <adorilson@gmail.com>
Wed, 11 Feb 2026 08:41:37 +0000 (08:41 +0000)
committerGitHub <noreply@github.com>
Wed, 11 Feb 2026 08:41:37 +0000 (09:41 +0100)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Doc/library/stdtypes.rst

index ffb5a053a6dce80e5d019b89090248b00ff0a4f3..c8dc834fe84446ea2848c7e8332a3215df74d448 100644 (file)
@@ -2630,14 +2630,17 @@ expression support in the :mod:`re` module).
    Return a copy of the string with trailing characters removed.  The *chars*
    argument is a string specifying the set of characters to be removed.  If omitted
    or ``None``, the *chars* argument defaults to removing whitespace.  The *chars*
-   argument is not a suffix; rather, all combinations of its values are stripped::
+   argument is not a suffix; rather, all combinations of its values are stripped.
+   For example:
+
+   .. doctest::
 
       >>> '   spacious   '.rstrip()
       '   spacious'
       >>> 'mississippi'.rstrip('ipz')
       'mississ'
 
-   See :meth:`str.removesuffix` for a method that will remove a single suffix
+   See :meth:`removesuffix` for a method that will remove a single suffix
    string rather than all of a set of characters.  For example::
 
       >>> 'Monty Python'.rstrip(' Python')
@@ -2645,6 +2648,9 @@ expression support in the :mod:`re` module).
       >>> 'Monty Python'.removesuffix(' Python')
       'Monty'
 
+   See also :meth:`strip`.
+
+
 .. method:: str.split(sep=None, maxsplit=-1)
 
    Return a list of the words in the string, using *sep* as the delimiter
@@ -2795,7 +2801,11 @@ expression support in the :mod:`re` module).
    The *chars* argument is a string specifying the set of characters to be removed.
    If omitted or ``None``, the *chars* argument defaults to removing whitespace.
    The *chars* argument is not a prefix or suffix; rather, all combinations of its
-   values are stripped::
+   values are stripped.
+
+   For example:
+
+   .. doctest::
 
       >>> '   spacious   '.strip()
       'spacious'
@@ -2806,12 +2816,17 @@ expression support in the :mod:`re` module).
    from the string. Characters are removed from the leading end until
    reaching a string character that is not contained in the set of
    characters in *chars*. A similar action takes place on the trailing end.
-   For example::
+
+   For example:
+
+   .. doctest::
 
       >>> comment_string = '#....... Section 3.2.1 Issue #32 .......'
       >>> comment_string.strip('.#! ')
       'Section 3.2.1 Issue #32'
 
+   See also :meth:`rstrip`.
+
 
 .. method:: str.swapcase()