Python String isupper()
Method
The isupper() method in Python is used to check if all the alphabetic characters in a string are uppercase. It’s one of the most useful string-checking methods when validating text inputs.
Syntax
string.isupper()
Parameters:
- None – This method does not take any arguments.
Returns:
True
– If all cased characters in the string are uppercase.False
– If there is at least one lowercase letter, or no cased characters at all.
Example 1: Simple Usage
text = "HELLO"
print(text.isupper())
True
Example 2: With Numbers and Symbols
text = "WELCOME123!"
print(text.isupper())
True
Numbers and symbols are ignored; only alphabetic characters are considered.
Example 3: Mixed Case String
text = "Hello"
print(text.isupper())
False
Example 4: No Alphabetic Characters
text = "12345!@#"
print(text.isupper())
False
If there are no alphabetic characters, isupper()
returns False
.
Use Case: Validating Uppercase Input
This method is often used when you want to ensure user input is in all capital letters – such as license plates, codes, or acronyms.
code = input("Enter secret code in uppercase: ")
if code.isupper():
print("Valid code.")
else:
print("Code must be in uppercase!")
Common Mistakes
- Thinking
isupper()
will convert the string – it only checks, it does not change anything. - Assuming it works with non-string types – you must call it on a string.
Interview Tip
isupper()
is commonly used in data validation or parsing logic where case sensitivity matters, such as password rules or form validations.
Summary
isupper()
checks if all letters in a string are uppercase.- It ignores numbers and special characters.
- Returns
False
if there are no letters at all.
Practice Problem
Write a Python program that asks the user to enter their name and prints a warning if the name is not in uppercase.
name = input("Enter your name in UPPERCASE: ")
if name.isupper():
print("Thank you!")
else:
print("Please enter your name in all uppercase.")