Use the isupper()
method to check if the characters in a string are all in upper case.
text = 'This is a regular text'
print(text.isupper())
#output: False
text = 'THIS IS A REGULAR TEXT'
print(text.isupper())
#output: True
text = 'THIS $ 1S @ A R3GULAR TEXT!'
print(text.isupper())
#output: True
If you notice the last example, the numbers and special characters like @
and $
in the string make no difference and isupper()
still returns True
because the method only verifies the alphabetical characters.