Skip to content

Commit 3c8c4e9

Browse files
[3.14] gh-106318: Add examples for str.replace() method (GH-143581) (GH-143789)
(cherry picked from commit af9f783) Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
1 parent 5d26a04 commit 3c8c4e9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/library/stdtypes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,14 @@ expression support in the :mod:`re` module).
25122512
Return a copy of the string with all occurrences of substring *old* replaced by
25132513
*new*. If *count* is given, only the first *count* occurrences are replaced.
25142514
If *count* is not specified or ``-1``, then all occurrences are replaced.
2515+
For example:
2516+
2517+
.. doctest::
2518+
2519+
>>> 'spam, spam, spam'.replace('spam', 'eggs')
2520+
'eggs, eggs, eggs'
2521+
>>> 'spam, spam, spam'.replace('spam', 'eggs', 1)
2522+
'eggs, spam, spam'
25152523

25162524
.. versionchanged:: 3.13
25172525
*count* is now supported as a keyword argument.

0 commit comments

Comments
 (0)