I want to know if all words in the list are all capitalized, that is, all alphabetical characters are capitalized.
I tried this for a simple string to understand behavior of isupper()
:
>>> 'FDSFS BBIBIFBIBWEF ASDASD 112,32:/'.isupper()
True
So I separated words in that sentence into list:
>>> sent = ['FDSFS','BBIBIFBIBWEF','ASDASD', '112','32:/']
>>> all([word.isupper() for word in sent])
False
So I checked the what was argument list to all()
contained:
>>> [word.isupper() for word in sent]
[True, True, True, False, False]
Weirdly, isupper()
returns False
for strings containing no alphabets (that is made up of only numbers and special characters), but returns True
if those strings are made to contain even a single capital character:
>>> '123'.isupper()
False
>>> '123A'.isupper()
True
>>> '123?A'.isupper()
True
>>> '123?'.isupper()
False
>>> ''.isupper()
False
Q1. Is there any design decision behind this behavior for isupper()
?
Q2. How can I achieve what I want to do in the most pythonic and minimal way? (Maybe there is any other function that just checks if all alphabetical words in the input string are capital and don't bother about special characters, numbers, and empty strings at all? Or do I have to write one from scratch?)