mirror of
https://github.com/python/cpython.git
synced 2026-06-18 07:32:45 +00:00
[3.14] gh-106318: Improve str.removeprefix() and str.removesuffix() docs (GH-143580) (#143614)
gh-106318: Improve str.removeprefix() and str.removesuffix() docs (GH-143580)
Add doctest role and 'See also'.
(cherry picked from commit 6d6c7ed737)
Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
This commit is contained in:
parent
1d0baf1ae4
commit
ae62d2bb31
1 changed files with 10 additions and 2 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue