How to check if a character is upper-case in Python?

PythonServer Side ProgrammingProgramming

To check if a character is upper-case, we can simply use isupper() function call on the said character. 

 example

print( 'Z'.isupper())
print( 'u'.isupper())

Output

True
False

We can also check it using range based if conditions. 

 example

def check_upper(c):
    if c >= 'A' and c <= 'Z':
        return True
    else:
        return False
print check_upper('A')
print check_upper('a')

Output

This will give us the output:

True
False
raja
Published on 11-Dec-2017 12:03:18
Advertisements