Skip to Content

How to Check if a Letter is Uppercase in Python

How to Check if a Letter is Uppercase in Python

Today, we will see how to check if a letter is uppercase in Python. You can easily do this using Python’s isupper() method.

The syntax is str.isupper(), i.e., it is invoked on the string that we want to check. It takes no parameters, and it returns True if all the characters in a string are capitalized.

If even one of the letters is lowercase, then it will return False. For this problem, we only have a single character.

Therefore, it will return True if the letter is uppercase. Otherwise, it will return False.

Let’s have a look at an example.

 

letter = "A"
is_upper = letter.isupper()
if is_upper:
  print(f"{letter} is in uppercase")
else:
  print(f"{letter} is not in uppercase")

 

Output

A is in uppercase

 

Consider another example.

 

letter = "o"
is_upper = letter.isupper()
if is_upper:
  print(f"{letter} is in uppercase")
else:
  print(f"{letter} is not in uppercase")

 

Output

 

o is not in uppercase

 

If we invoke this method on an empty string (no character) or a string that does not have any English alphabets, then it will return False. Let’s see.

 

checks=["", " ", "@", "MY NAME IS @", "2@!"]
for string in checks:
  is_upper = string.isupper()
  if is_upper:
    print(f"'{string}' is in uppercase")
  else:
    print(f"'{string}' is not in uppercase")

 

'' is not in uppercase
' ' is not in uppercase
'@' is not in uppercase
'MY NAME IS @' is in uppercase
'2@!' is not in uppercase