Check if all characters of a string are uppercase
You should use str.isupper()
and str.isalpha()
function.
Eg.
is_all_uppercase = word.isupper() and word.isalpha()
According to the docs:
S.isupper() -> bool
Return
True
if all cased characters inS
are uppercase and there is at least one cased character inS
,False
otherwise.
You could use regular expressions:
all_uppercase = bool(re.match(r'[A-Z]+$', word))