Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107887 > unrolled thread

Re: Not x.islower() has different output than x.isupper() in list output...

Started byChris Angelico <rosuav@gmail.com>
First post2016-04-30 12:10 +1000
Last post2016-04-30 12:10 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Not x.islower() has different output than x.isupper() in list output... Chris Angelico <rosuav@gmail.com> - 2016-04-30 12:10 +1000

#107887 — Re: Not x.islower() has different output than x.isupper() in list output...

FromChris Angelico <rosuav@gmail.com>
Date2016-04-30 12:10 +1000
SubjectRe: Not x.islower() has different output than x.isupper() in list output...
Message-ID<mailman.244.1461982253.32212.python-list@python.org>
On Sat, Apr 30, 2016 at 11:55 AM, Christopher Reimer
<christopher_reimer@icloud.com> wrote:
> On 4/29/2016 6:29 PM, Stephen Hansen wrote:
>>
>> If isupper/islower were perfect opposites of each-other, there'd be no
>> need for both. But since characters can be upper, lower, or *neither*, you
>> run into this situation.
>
>
> Based upon the official documentation, I was expecting perfect opposites.
>
> str.islower(): "Return true if all cased characters [4] in the string are
> lowercase and there is at least one cased character, false otherwise."
>
> https://docs.python.org/3/library/stdtypes.html?highlight=islower#str.islower
>
> str.isupper(): "Return true if all cased characters [4] in the string are
> uppercase and there is at least one cased character, false otherwise."
>
> https://docs.python.org/3/library/stdtypes.html?highlight=isupper#str.isupper
>
> Here's the footnote that may or not be relevant to this discussion: "[4]
> Cased characters are those with general category property being one of “Lu”
> (Letter, uppercase), “Ll” (Letter, lowercase), or “Lt” (Letter, titlecase)."
>
> A bug in the docs?

>>> def case(ch):
...     return (
...         ("Lower " if ch.islower() else "") +
...         ("Upper " if ch.isupper() else "") +
...         unicodedata.category(ch)
...     )

Both functions require that there be at least one cased character:

>>> case("@")
'Po'

And then each one requires a specific character class:

>>> case("a")
'Lower Ll'
>>> case("A")
'Upper Lu'

Other classes don't count:

>>> case("\u01C5")
'Lt'

There are three categories of "cased characters". Both functions check
for exactly one of those categories. Thus they are not opposites.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web