mirror of
https://github.com/python/cpython.git
synced 2026-02-16 20:31:37 +00:00
[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:
parent
5d26a0410e
commit
3c8c4e98da
1 changed files with 8 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue