Skip to content

Commit db8254a

Browse files
committed
gh-106318: Add examples for str.upper() method and improve related
1 parent fd190d1 commit db8254a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

Doc/library/stdtypes.rst

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,10 @@ expression support in the :mod:`re` module).
23742374
Return ``True`` if all cased characters [4]_ in the string are uppercase and
23752375
there is at least one cased character, ``False`` otherwise.
23762376

2377+
For example:
2378+
2379+
.. doctest::
2380+
23772381
>>> 'BANANA'.isupper()
23782382
True
23792383
>>> 'banana'.isupper()
@@ -2383,6 +2387,7 @@ expression support in the :mod:`re` module).
23832387
>>> ' '.isupper()
23842388
False
23852389

2390+
See also :meth:`islower` and :meth:`upper`.
23862391

23872392

23882393
.. _meth-str-join:
@@ -2438,6 +2443,8 @@ expression support in the :mod:`re` module).
24382443
Conversion' of the Unicode Standard
24392444
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G34078>`__.
24402445

2446+
See also :meth:`islower` and :meth:`upper`.
2447+
24412448

24422449
.. method:: str.lstrip(chars=None, /)
24432450

@@ -2877,15 +2884,34 @@ expression support in the :mod:`re` module).
28772884
.. method:: str.upper()
28782885

28792886
Return a copy of the string with all the cased characters [4]_ converted to
2880-
uppercase. Note that ``s.upper().isupper()`` might be ``False`` if ``s``
2887+
uppercase.
2888+
2889+
For example:
2890+
2891+
.. doctest::
2892+
2893+
>>> 'Upper Method Example'.upper()
2894+
'UPPER METHOD EXAMPLE'
2895+
2896+
Note that ``s.upper().isupper()`` might be ``False`` if ``s``
28812897
contains uncased characters or if the Unicode category of the resulting
28822898
character(s) is not "Lu" (Letter, uppercase), but e.g. "Lt" (Letter,
28832899
titlecase).
28842900

2901+
For example, see the word "Python" written in Punjabi, the most spoken language
2902+
in Pakistan:
2903+
2904+
.. doctest::
2905+
2906+
>>> 'ازگر'.upper().isupper()
2907+
False
2908+
28852909
The uppercasing algorithm used is `described in section 3.13.2 'Default Case
28862910
Conversion' of the Unicode Standard
28872911
<https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G34078>`__.
28882912

2913+
See also :meth:`isupper` and :meth:`lower`.
2914+
28892915

28902916
.. method:: str.zfill(width, /)
28912917

0 commit comments

Comments
 (0)