[3.14] gh-106318: Add examples for str.replace() method (GH-143581) (GH-143789)

(cherry picked from commit af9f783a7e)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
This commit is contained in:
Miss Islington (bot) 2026-01-13 13:22:49 +01:00 committed by GitHub
parent 5d26a0410e
commit 3c8c4e98da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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.