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'
.. 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'
.. versionadded:: 3.9
+ See also :meth:`removeprefix` and :meth:`endswith`.
+
.. method:: str.replace(old, new, /, count=-1)