
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
Hey guys! It’s me, Marcel, aka Maschi. I earn a full-time income online and on MaschiTuts I gladly share with you guys how I stay on top of the game! I run several highly profitable blogs & websites and love to speak about these project whenever I get a chance to do so. I do this full-time and wholeheartedly. In fact, the moment I stopped working an 8-to-5 job and finally got into online business as a digital entrepreneur, is problably one of the best decisions I ever took in my life. And I would like to make sure that YOU can get on this path as well! Don’t let anyone tell you that this can’t be done. Sky’s the limit, really…as long as you BELIEVE in it! And it all starts right here..at Maschituts!