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

736 Views Asked by At

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

1

There are 1 best solutions below

5
On

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.