Skip to content

Commit c617374

Browse files
committed
pythongh-106318: Add doctest role for str.title() examples
1 parent 6665115 commit c617374

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎Doc/library/stdtypes.rst‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,15 +2801,19 @@ expression support in the :mod:`re` module).
28012801
Return a titlecased version of the string where words start with an uppercase
28022802
character and the remaining characters are lowercase.
28032803

2804-
For example::
2804+
For example:
2805+
2806+
.. doctest::
28052807

28062808
>>> 'Hello world'.title()
28072809
'Hello World'
28082810

28092811
The algorithm uses a simple language-independent definition of a word as
28102812
groups of consecutive letters. The definition works in many contexts but
28112813
it means that apostrophes in contractions and possessives form word
2812-
boundaries, which may not be the desired result::
2814+
boundaries, which may not be the desired result:
2815+
2816+
.. doctest::
28132817

28142818
>>> "they're bill's friends from the UK".title()
28152819
"They'Re Bill'S Friends From The Uk"
@@ -2818,7 +2822,9 @@ expression support in the :mod:`re` module).
28182822
splits words on spaces only.
28192823

28202824
Alternatively, a workaround for apostrophes can be constructed using regular
2821-
expressions::
2825+
expressions:
2826+
2827+
.. doctest::
28222828

28232829
>>> import re
28242830
>>> def titlecase(s):
@@ -2829,7 +2835,7 @@ expression support in the :mod:`re` module).
28292835
>>> titlecase("they're bill's friends.")
28302836
"They're Bill's Friends."
28312837

2832-
See also :meth:`istitle`.
2838+
See also :meth:`istitle` and :meth:`capitalize`.
28332839

28342840

28352841
.. method:: str.translate(table, /)

0 commit comments

Comments
 (0)