0
$\begingroup$

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

$\endgroup$
1
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.