From 8a508e095b457849a309231cb19e6cf9303485b7 Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 12 May 2021 19:35:29 -0300 Subject: [PATCH 1/2] [Doc] Added snippet code to str.replace method --- Doc/library/stdtypes.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ae197f765d1e16..82b86e8a342853 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2402,6 +2402,12 @@ expression support in the :mod:`re` module). .. versionchanged:: 3.13 *count* is now supported as a keyword argument. + For example:: + + >>> 'spam, spam, spam'.replace('spam', 'eggs') + 'eggs, eggs, eggs' + >>> 'spam, spam, spam'.replace('spam', 'eggs', 1) + 'eggs, spam, spam' .. method:: str.rfind(sub[, start[, end]]) From 6272577e4897aaf9198288822aa676de0f69d26b Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Thu, 8 Jan 2026 20:00:20 +0000 Subject: [PATCH 2/2] gh-106318: Add examples for str.replace() method --- Doc/library/stdtypes.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 82b86e8a342853..e7c757405371c3 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2398,17 +2398,19 @@ 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: - .. versionchanged:: 3.13 - *count* is now supported as a keyword argument. - - 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. + + .. method:: str.rfind(sub[, start[, end]]) Return the highest index in the string where substring *sub* is found, such