Skip to content

Commit 762b8ec

Browse files
authored
gh-106318: Add examples for str.upper() method and improve related (GH-144638)
1 parent dd3f5cd commit 762b8ec

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

‎Doc/builtins/stdtypes.rst‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,10 @@ expression support in the :mod:`re` module).
26292629
Return ``True`` if all cased characters [4]_ in the string are uppercase and
26302630
there is at least one cased character, ``False`` otherwise.
26312631

2632+
For example:
2633+
2634+
.. doctest::
2635+
26322636
>>> 'BANANA'.isupper()
26332637
True
26342638
>>> 'banana'.isupper()
@@ -2696,6 +2700,8 @@ expression support in the :mod:`re` module).
26962700
Conversion' of the Unicode Standard
26972701
<https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-3/#G34078>`__.
26982702

2703+
See also :meth:`islower` and :meth:`upper`.
2704+
26992705

27002706
.. method:: str.lstrip(chars=None, /)
27012707

@@ -3199,15 +3205,33 @@ expression support in the :mod:`re` module).
31993205
.. method:: str.upper()
32003206

32013207
Return a copy of the string with all the cased characters [4]_ converted to
3202-
uppercase. Note that ``s.upper().isupper()`` might be ``False`` if ``s``
3208+
uppercase.
3209+
3210+
For example:
3211+
3212+
.. doctest::
3213+
3214+
>>> 'Upper Method Example'.upper()
3215+
'UPPER METHOD EXAMPLE'
3216+
3217+
Note that ``s.upper().isupper()`` might be ``False`` if ``s``
32033218
contains no cased characters or if the Unicode category of the resulting
3204-
character(s) is not "Lu" (Letter, uppercase), but e.g. "Lt" (Letter,
3219+
character(s) is not "Lu" (Letter, uppercase), but for instance "Lt" (Letter,
32053220
titlecase).
32063221

3222+
For example, see the word "Python" written in Punjabi:
3223+
3224+
.. doctest::
3225+
3226+
>>> 'ازگر'.upper().isupper()
3227+
False
3228+
32073229
The uppercasing algorithm used is `described in section 3.13.2 'Default Case
32083230
Conversion' of the Unicode Standard
32093231
<https://www.unicode.org/versions/Unicode18.0.0/core-spec/chapter-3/#G34078>`__.
32103232

3233+
See also :meth:`isupper` and :meth:`lower`.
3234+
32113235

32123236
.. method:: str.zfill(width, /)
32133237

0 commit comments

Comments
 (0)