From 2866c43a1c24e994a737f18428e7105b894bdf2e Mon Sep 17 00:00:00 2001 From: Adorilson Bezerra Date: Wed, 2 Dec 2026 12:42:18 -0300 Subject: [PATCH] [3.14] gh-106318: Add examples for str.upper() method and improve related (GH-144638) (cherry picked from commit 762b8ec11383f7297bcde566260528e2710ecbfd) Co-authored-by: Adorilson Bezerra --- Doc/builtins/stdtypes.rst | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Doc/builtins/stdtypes.rst b/Doc/builtins/stdtypes.rst index db5c4316b6946f..7e35373ede6b4b 100644 --- a/Doc/builtins/stdtypes.rst +++ b/Doc/builtins/stdtypes.rst @@ -2358,6 +2358,10 @@ expression support in the :mod:`re` module). Return ``True`` if all cased characters [4]_ in the string are uppercase and there is at least one cased character, ``False`` otherwise. + For example: + + .. doctest:: + >>> 'BANANA'.isupper() True >>> 'banana'.isupper() @@ -2425,6 +2429,8 @@ expression support in the :mod:`re` module). `described in section 3.13 'Default Case Folding' of the Unicode Standard `__. + See also :meth:`islower` and :meth:`upper`. + .. method:: str.lstrip(chars=None, /) @@ -2916,15 +2922,33 @@ expression support in the :mod:`re` module). .. method:: str.upper() Return a copy of the string with all the cased characters [4]_ converted to - uppercase. Note that ``s.upper().isupper()`` might be ``False`` if ``s`` + uppercase. + + For example: + + .. doctest:: + + >>> 'Upper Method Example'.upper() + 'UPPER METHOD EXAMPLE' + + Note that ``s.upper().isupper()`` might be ``False`` if ``s`` contains no cased characters or if the Unicode category of the resulting - character(s) is not "Lu" (Letter, uppercase), but e.g. "Lt" (Letter, + character(s) is not "Lu" (Letter, uppercase), but for instance "Lt" (Letter, titlecase). + For example, see the word "Python" written in Punjabi: + + .. doctest:: + + >>> 'ازگر'.upper().isupper() + False + The uppercasing algorithm used is `described in section 3.13 'Default Case Folding' of the Unicode Standard `__. + See also :meth:`isupper` and :meth:`lower`. + .. method:: str.zfill(width, /)