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.
Yash Mehrotra has the best answer for that problem, but if you'd also like to know how to check that without the methods, for purely educational reasons:
import stringdef is_all_uppercase(a_str): for c in a_str: if c not in string.ascii_uppercase: return False return True