# What is the difference between the following two tests: w.isupper () and not w.islower ()?

It's a question at the crossroads between computing and set theory

I just immersed myself in the Python documentation to answer this question

Let say $w$ is a string. What is the difference between the following two tests: w.isupper () and not w.islower ()

For me, the difference is that, in mathematical terms, w.isupper () means $$∀x ∈ w, x∈ Upper$$

not w.islower () means

$$∃ x ∈ w, x ∉ Lower$$

I do not know if it is enough for everyone to say that it is different, it is Set theory and, sometimes, I really need time to understand it. Also, there may be other computational or python reasons that I do not know

This question is from chapter 1 of Natural Language Processing with Python

Assuming w is a string (or a byte array or something similar), the docs say following:

str.isupper()

Return true if all cased characters in the string are uppercase and there is at least one cased character, false otherwise.

And

str.islower()

Return true if all cased characters in the string are lowercase and there is at least one cased character, false otherwise.

So w.isupper() checks whether all characters are in uppercase, while w.islower checks whether all characters are in lowercase. Therefore not w.islower() checks whether there is at least one uppercase character.

This is exactly what you've guessed in your post.

• Yes but what about w = a?b Aug 4 '18 at 10:19
• What is a?b? Consider posting further questions as seperate posts. Aug 4 '18 at 10:29
• a?b It's a string, it's still the same question Aug 4 '18 at 10:34
• @Marine1: a?b may be Python syntax for some string, but we're not Python experts enough to know which string that is ... Aug 4 '18 at 10:55
• @Marine1 if w = a?b and a?b is a string, then so is w, and the answer is also the same. Aug 4 '18 at 13:25