]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-106318: Add examples for str.replace() method (GH-143581) (GH-143788)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 13 Jan 2026 12:23:26 +0000 (13:23 +0100)
committerGitHub <noreply@github.com>
Tue, 13 Jan 2026 12:23:26 +0000 (12:23 +0000)
(cherry picked from commit af9f783a7e9bfdca94ce5b9619c1b82a32d9e170)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
Doc/library/stdtypes.rst

index 308da5eb1aa6b1e4d0614f17eb092208883062df..34e27f72d6ff5cee7c4e9903007cf6a137c2b006 100644 (file)
@@ -2271,6 +2271,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.