Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0656a56

Browse files
committed
#12204: document that str.upper().isupper() might be False and add a note about cased characters.
1 parent ee8d998 commit 0656a56

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ following values are considered false:
5454

5555
* instances of user-defined classes, if the class defines a :meth:`__bool__` or
5656
:meth:`__len__` method, when that method returns the integer zero or
57-
:class:`bool` value ``False``. [#]_
57+
:class:`bool` value ``False``. [1]_
5858

5959
.. index:: single: true
6060

@@ -261,7 +261,7 @@ Python fully supports mixed arithmetic: when a binary arithmetic operator has
261261
operands of different numeric types, the operand with the "narrower" type is
262262
widened to that of the other, where integer is narrower than floating point,
263263
which is narrower than complex. Comparisons between numbers of mixed type use
264-
the same rule. [#]_ The constructors :func:`int`, :func:`float`, and
264+
the same rule. [2]_ The constructors :func:`int`, :func:`float`, and
265265
:func:`complex` can be used to produce numbers of a specific type.
266266

267267
All numeric types (except complex) support the following operations, sorted by
@@ -852,7 +852,7 @@ them is inefficient.
852852
Most sequence types support the following operations. The ``in`` and ``not in``
853853
operations have the same priorities as the comparison operations. The ``+`` and
854854
``*`` operations have the same priority as the corresponding numeric operations.
855-
[#]_ Additional methods are provided for :ref:`typesseq-mutable`.
855+
[3]_ Additional methods are provided for :ref:`typesseq-mutable`.
856856

857857
This table lists the sequence operations sorted in ascending priority
858858
(operations in the same box have the same priority). In the table, *s* and *t*
@@ -1137,10 +1137,8 @@ functions based on regular expressions.
11371137

11381138
.. method:: str.islower()
11391139

1140-
Return true if all cased characters in the string are lowercase and there is at
1141-
least one cased character, false otherwise. Cased characters are those with
1142-
general category property being one of "Lu", "Ll", or "Lt" and lowercase characters
1143-
are those with general category property "Ll".
1140+
Return true if all cased characters [4]_ in the string are lowercase and
1141+
there is at least one cased character, false otherwise.
11441142

11451143

11461144
.. method:: str.isnumeric()
@@ -1180,10 +1178,8 @@ functions based on regular expressions.
11801178

11811179
.. method:: str.isupper()
11821180

1183-
Return true if all cased characters in the string are uppercase and there is at
1184-
least one cased character, false otherwise. Cased characters are those with
1185-
general category property being one of "Lu", "Ll", or "Lt" and uppercase characters
1186-
are those with general category property "Lu".
1181+
Return true if all cased characters [4]_ in the string are uppercase and
1182+
there is at least one cased character, false otherwise.
11871183

11881184

11891185
.. method:: str.join(iterable)
@@ -1203,7 +1199,8 @@ functions based on regular expressions.
12031199

12041200
.. method:: str.lower()
12051201

1206-
Return a copy of the string converted to lowercase.
1202+
Return a copy of the string with all the cased characters [4]_ converted to
1203+
lowercase.
12071204

12081205

12091206
.. method:: str.lstrip([chars])
@@ -1404,7 +1401,10 @@ functions based on regular expressions.
14041401

14051402
.. method:: str.upper()
14061403

1407-
Return a copy of the string converted to uppercase.
1404+
Return a copy of the string with all the cased characters [4]_ converted to
1405+
uppercase. Note that ``str.upper().isupper()`` might be ``False`` if ``s``
1406+
contains uncased characters or if the Unicode category of the resulting
1407+
character(s) is not "Lu" (Letter, uppercase), but e.g. "Lt" (Letter, titlecase).
14081408

14091409

14101410
.. method:: str.zfill(width)
@@ -1444,7 +1444,7 @@ specifications in *format* are replaced with zero or more elements of *values*.
14441444
The effect is similar to the using :c:func:`sprintf` in the C language.
14451445

14461446
If *format* requires a single argument, *values* may be a single non-tuple
1447-
object. [#]_ Otherwise, *values* must be a tuple with exactly the number of
1447+
object. [5]_ Otherwise, *values* must be a tuple with exactly the number of
14481448
items specified by the format string, or a single mapping object (for example, a
14491449
dictionary).
14501450

@@ -2808,13 +2808,16 @@ The following attributes are only supported by :term:`new-style class`\ es.
28082808

28092809
.. rubric:: Footnotes
28102810

2811-
.. [#] Additional information on these special methods may be found in the Python
2811+
.. [1] Additional information on these special methods may be found in the Python
28122812
Reference Manual (:ref:`customization`).
28132813
2814-
.. [#] As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0]``, and
2814+
.. [2] As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0]``, and
28152815
similarly for tuples.
28162816
2817-
.. [#] They must have since the parser can't tell the type of the operands.
2817+
.. [3] They must have since the parser can't tell the type of the operands.
28182818
2819-
.. [#] To format only a tuple you should therefore provide a singleton tuple whose only
2819+
.. [4] Cased characters are those with general category property being one of
2820+
"Lu" (Letter, uppercase), "Ll" (Letter, lowercase), or "Lt" (Letter, titlecase).
2821+
2822+
.. [5] To format only a tuple you should therefore provide a singleton tuple whose only
28202823
element is the tuple to be formatted.

0 commit comments

Comments
 (0)