Skip to content

Commit 1c06261

Browse files
[3.15] gh-106318: Add examples for str.upper() method and improve related (GH-144638) (#163021)
gh-106318: Add examples for str.upper() method and improve related (GH-144638) (cherry picked from commit 762b8ec) Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
1 parent 1f92619 commit 1c06261

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
@@ -2612,6 +2612,10 @@ expression support in the :mod:`re` module).
26122612
Return ``True`` if all cased characters [4]_ in the string are uppercase and
26132613
there is at least one cased character, ``False`` otherwise.
26142614

2615+
For example:
2616+
2617+
.. doctest::
2618+
26152619
>>> 'BANANA'.isupper()
26162620
True
26172621
>>> 'banana'.isupper()
@@ -2676,6 +2680,8 @@ expression support in the :mod:`re` module).
26762680
Conversion' of the Unicode Standard
26772681
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G34078>`__.
26782682

2683+
See also :meth:`islower` and :meth:`upper`.
2684+
26792685

26802686
.. method:: str.lstrip(chars=None, /)
26812687

@@ -3179,15 +3185,33 @@ expression support in the :mod:`re` module).
31793185
.. method:: str.upper()
31803186

31813187
Return a copy of the string with all the cased characters [4]_ converted to
3182-
uppercase. Note that ``s.upper().isupper()`` might be ``False`` if ``s``
3188+
uppercase.
3189+
3190+
For example:
3191+
3192+
.. doctest::
3193+
3194+
>>> 'Upper Method Example'.upper()
3195+
'UPPER METHOD EXAMPLE'
3196+
3197+
Note that ``s.upper().isupper()`` might be ``False`` if ``s``
31833198
contains no cased characters or if the Unicode category of the resulting
3184-
character(s) is not "Lu" (Letter, uppercase), but e.g. "Lt" (Letter,
3199+
character(s) is not "Lu" (Letter, uppercase), but for instance "Lt" (Letter,
31853200
titlecase).
31863201

3202+
For example, see the word "Python" written in Punjabi:
3203+
3204+
.. doctest::
3205+
3206+
>>> 'ازگر'.upper().isupper()
3207+
False
3208+
31873209
The uppercasing algorithm used is `described in section 3.13.2 'Default Case
31883210
Conversion' of the Unicode Standard
31893211
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G34078>`__.
31903212

3213+
See also :meth:`isupper` and :meth:`lower`.
3214+
31913215

31923216
.. method:: str.zfill(width, /)
31933217

0 commit comments

Comments
 (0)