]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106318: Add examples for str.replace() method (GH-143581)
authorAdorilson Bezerra <adorilson@gmail.com>
Fri, 9 Jan 2026 08:01:00 +0000 (08:01 +0000)
committerGitHub <noreply@github.com>
Fri, 9 Jan 2026 08:01:00 +0000 (09:01 +0100)
Doc/library/stdtypes.rst

index ae197f765d1e16bf91d093d5383dc09b163f2cf1..e7c757405371c3f32ece632cb01b41cc6edd752d 100644 (file)
@@ -2398,6 +2398,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.