Skip to content

Commit cbf08d5

Browse files
[3.13] gh-106318: Add examples for str.replace() method (GH-143581) (GH-143788)
(cherry picked from commit af9f783) Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
1 parent b739bd1 commit cbf08d5

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
@@ -2271,6 +2271,14 @@ expression support in the :mod:`re` module).
22712271
Return a copy of the string with all occurrences of substring *old* replaced by
22722272
*new*. If *count* is given, only the first *count* occurrences are replaced.
22732273
If *count* is not specified or ``-1``, then all occurrences are replaced.
2274+
For example:
2275+
2276+
.. doctest::
2277+
2278+
>>> 'spam, spam, spam'.replace('spam', 'eggs')
2279+
'eggs, eggs, eggs'
2280+
>>> 'spam, spam, spam'.replace('spam', 'eggs', 1)
2281+
'eggs, spam, spam'
22742282

22752283
.. versionchanged:: 3.13
22762284
*count* is now supported as a keyword argument.

0 commit comments

Comments
 (0)