Check if a string is uppercase in Python

You can check if a string is uppercase in Python. Note that a string is uppercase if all the letters are uppercase in Python.

a = 'apple'
b = 'Apple'
c = 'APPLE'

if a.isupper():
    print('a is uppercase')
if b.isupper():
    print('b is uppercase')
if c.isupper():
    print('c is uppercase')

# c is uppercase

The isupper() returns true if the string is uppercase. The last string is only uppercase so c is uppercase was printed.

Python String

Python Tutorial