From 2194efe33e761ae06579103d17af74bde44389fa Mon Sep 17 00:00:00 2001 From: blaisep Date: Mon, 19 May 2025 15:06:16 -0400 Subject: [PATCH 1/2] Add an example for `str.capitalize` for #106318 This is the smallest possible step toward adding examples for the string methods. The content was contributed by @adorilson in #105670 Because https://github.com/python/cpython/pull/119445 is big and difficult to review, this PR will be updated as the individual examples get merged. --- Doc/library/stdtypes.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 3486a18b5cb1f0..f5dc916961635f 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1759,7 +1759,14 @@ expression support in the :mod:`re` module). .. method:: str.capitalize() Return a copy of the string with its first character capitalized and the - rest lowercased. + rest lowercased. For example:: + + >>> 'PYTHON IS AMAZING'.capitalize() + 'Python is amazing' + >>> 'Njemačka Starts With a non-english Digraph'.capitalize() + 'Njemačka starts with a non-english digraph' + + See also :meth:`title`. .. versionchanged:: 3.8 The first character is now put into titlecase rather than uppercase. From 41bc9bc833b7d9edccb1efb42f2567649d8d13ee Mon Sep 17 00:00:00 2001 From: blaisep Date: Mon, 19 May 2025 16:58:02 -0400 Subject: [PATCH 2/2] Replace the city name in the example. The suggestion was to use a example where there was a bigger contrast between the uppercase in the input stream and the mixed case in the result. --- Doc/library/stdtypes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index f5dc916961635f..30943b64fd1c0a 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1763,8 +1763,8 @@ expression support in the :mod:`re` module). >>> 'PYTHON IS AMAZING'.capitalize() 'Python is amazing' - >>> 'Njemačka Starts With a non-english Digraph'.capitalize() - 'Njemačka starts with a non-english digraph' + >>> 'LJjubljana starts With a non-english digraph'.capitalize() + 'Ljjubljana starts with a non-english digraph' See also :meth:`title`.