@@ -1844,6 +1844,14 @@ expression support in the :mod:`re` module).
18441844 lowercase letter ``'ß' `` is equivalent to ``"ss" ``. Since it is already
18451845 lowercase, :meth: `lower ` would do nothing to ``'ß' ``; :meth: `casefold `
18461846 converts it to ``"ss" ``.
1847+ For example:
1848+
1849+ .. doctest ::
1850+
1851+ >>> ' straße' .lower()
1852+ 'straße'
1853+ >>> ' straße' .casefold()
1854+ 'strasse'
18471855
18481856 The casefolding algorithm is `described in section 3.13.3 'Default Case
18491857 Folding' of the Unicode Standard
@@ -2045,7 +2053,18 @@ expression support in the :mod:`re` module).
20452053.. method :: str.index(sub[, start[, end]])
20462054
20472055 Like :meth: `~str.find `, but raise :exc: `ValueError ` when the substring is
2048- not found.
2056+ not found. For example:
2057+
2058+ .. doctest ::
2059+
2060+ >>> ' spam, spam, spam' .index(' eggs' )
2061+ Traceback (most recent call last):
2062+ File "<python-input-0>", line 1, in <module>
2063+ 'spam, spam, spam'.index('eggs')
2064+ ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
2065+ ValueError: substring not found
2066+
2067+ See also :meth: `rindex `.
20492068
20502069
20512070.. method :: str.isalnum()
@@ -2289,7 +2308,12 @@ expression support in the :mod:`re` module).
22892308.. method :: str.lower()
22902309
22912310 Return a copy of the string with all the cased characters [4 ]_ converted to
2292- lowercase.
2311+ lowercase. For example:
2312+
2313+ .. doctest ::
2314+
2315+ >>> ' Lower Method Example' .lower()
2316+ 'lower method example'
22932317
22942318 The lowercasing algorithm used is `described in section 3.13.2 'Default Case
22952319 Conversion' of the Unicode Standard
@@ -2345,7 +2369,9 @@ expression support in the :mod:`re` module).
23452369
23462370 If the string starts with the *prefix * string, return
23472371 ``string[len(prefix):] ``. Otherwise, return a copy of the original
2348- string::
2372+ string:
2373+
2374+ .. doctest ::
23492375
23502376 >>> ' TestHook' .removeprefix(' Test' )
23512377 'Hook'
@@ -2354,12 +2380,16 @@ expression support in the :mod:`re` module).
23542380
23552381 .. versionadded :: 3.9
23562382
2383+ See also :meth: `removesuffix ` and :meth: `startswith `.
2384+
23572385
23582386.. method :: str.removesuffix(suffix, /)
23592387
23602388 If the string ends with the *suffix * string and that *suffix * is not empty,
23612389 return ``string[:-len(suffix)] ``. Otherwise, return a copy of the
2362- original string::
2390+ original string:
2391+
2392+ .. doctest ::
23632393
23642394 >>> ' MiscTests' .removesuffix(' Tests' )
23652395 'Misc'
@@ -2368,12 +2398,22 @@ expression support in the :mod:`re` module).
23682398
23692399 .. versionadded :: 3.9
23702400
2401+ See also :meth: `removeprefix ` and :meth: `endswith `.
2402+
23712403
23722404.. method :: str.replace(old, new, /, count=-1)
23732405
23742406 Return a copy of the string with all occurrences of substring *old * replaced by
23752407 *new *. If *count * is given, only the first *count * occurrences are replaced.
23762408 If *count * is not specified or ``-1 ``, then all occurrences are replaced.
2409+ For example:
2410+
2411+ .. doctest ::
2412+
2413+ >>> ' spam, spam, spam' .replace(' spam' , ' eggs' )
2414+ 'eggs, eggs, eggs'
2415+ >>> ' spam, spam, spam' .replace(' spam' , ' eggs' , 1 )
2416+ 'eggs, spam, spam'
23772417
23782418 .. versionchanged :: 3.13
23792419 *count * is now supported as a keyword argument.
@@ -2384,6 +2424,16 @@ expression support in the :mod:`re` module).
23842424 Return the highest index in the string where substring *sub * is found, such
23852425 that *sub * is contained within ``s[start:end] ``. Optional arguments *start *
23862426 and *end * are interpreted as in slice notation. Return ``-1 `` on failure.
2427+ For example:
2428+
2429+ .. doctest ::
2430+
2431+ >>> ' spam, spam, spam' .rfind(' sp' )
2432+ 12
2433+ >>> ' spam, spam, spam' .rfind(' sp' , 0 , 10 )
2434+ 6
2435+
2436+ See also :meth: `find ` and :meth: `rindex `.
23872437
23882438
23892439.. method :: str.rindex(sub[, start[, end]])
0 commit comments