Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-106318: Add examples for str.replace() method (GH-143581)
(cherry picked from commit af9f783)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
  • Loading branch information
adorilson authored and miss-islington committed Jan 13, 2026
commit de50128b8d9b5327f952c8c89f41c4efac965736
8 changes: 8 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,14 @@ expression support in the :mod:`re` module).
Return a copy of the string with all occurrences of substring *old* replaced by
*new*. If *count* is given, only the first *count* occurrences are replaced.
If *count* is not specified or ``-1``, then all occurrences are replaced.
For example:

.. doctest::

>>> 'spam, spam, spam'.replace('spam', 'eggs')
'eggs, eggs, eggs'
>>> 'spam, spam, spam'.replace('spam', 'eggs', 1)
'eggs, spam, spam'

.. versionchanged:: 3.13
*count* is now supported as a keyword argument.
Expand Down
Loading