In this tutorial, I will explain how to check if a string is all uppercase in Python. As a Python developer creating an application for a customer service platform for one of my clients in the USA, I encountered a requirement to check string is all uppercase. After exploring Python’s string methods, I discovered a simple and efficient way to achieve this task, which I will explain below.
Check if a String is All Uppercase in Python
Python provides various ways to check if a string is All uppercase in Python. Let us see some important methods.
Read How to Check if a String Ends with a Pattern in Python?
1. Use the isupper() Method
Python provides a built-in method isupper() that can be used to check if all characters in a string are uppercase.
Example:
text = "HELLO AMERICA"
if text.isupper():
print("The string is all uppercase.")
else:
print("The string is not all uppercase.")Output:
The string is all uppercase.I have executed the above example code and added the screenshot below.

This method returns True if all alphabetic characters in the string are uppercase, and there are no lowercase letters. Non-alphabetic characters are ignored.
Read How to Check if a String Starts with a Specific Substring in Python?
Handle Mixed Content
The isupper() method only checks alphabetic characters. If the string contains numbers, punctuation, or spaces, they do not affect the result.
text = "WELCOME TO NEW YORK 2024!"
if text.isupper():
print("The string is all uppercase.")
else:
print("The string is not all uppercase.")Output:
The string is all uppercase.I have executed the above example code and added the screenshot below.

Read How to Check if a String is an Integer or Float in Python?
Check Each Character Individually
Sometimes, you may want more control over the validation process. You can iterate through each character in the string and check if it is uppercase using the isupper() method.
Example:
text = "CALIFORNIA"
all_upper = True
for char in text:
if char.isalpha() and not char.isupper():
all_upper = False
break
if all_upper:
print("The string is all uppercase.")
else:
print("The string is not all uppercase.")Output:
The string is all uppercase.I have executed the above example code and added the screenshot below.

In this example, we manually check each character to determine if the string is all uppercase.
Read How to Check if a String is Empty or NaN in Python?
2. Use Regular Expressions
For more complex scenarios, regular expressions (regex) can be a powerful tool. Python’s re module allows you to use regex to match patterns in strings.
Example:
import re
text = "WASHINGTON DC"
pattern = r'^[A-Z\s]+$'
if re.match(pattern, text):
print("The string is all uppercase.")
else:
print("The string is not all uppercase.")Output:
The string is all uppercase.I have executed the above example code and added the screenshot below.

In this example, the regex pattern ^[A-Z\s]+$ matches strings that contain only uppercase letters and spaces.
Read Convert Binary to Decimal in Python
Application: User Input Validation
Imagine you are developing a web application where users need to enter their state names in uppercase. You can use the isupper() method to validate the input.
Example:
def validate_state_name(state_name):
if state_name.isupper():
return "Valid state name."
else:
return "Invalid state name. Please enter the state name in uppercase."
# User input
user_input = "TEXAS"
print(validate_state_name(user_input))
user_input = "Texas"
print(validate_state_name(user_input))Output:
Valid state name.
Invalid state name. Please enter the state name in uppercase.Read How to Compare Strings in Python?
Common Issues and Best Practices
Let us see some common pitfalls and best practices.
Issue: Ignore Non-Alphabetic Characters
Remember that the isupper() method ignores non-alphabetic characters. If your validation requires that the entire string (including numbers and punctuation) be in uppercase, you need to handle these cases separately.
Read Find the First Number in a String in Python
Best Practice: Combine Methods
For robust validation, consider combining multiple methods. For example, use isupper() for initial checks and regex for more complex patterns.
Example of Combined Methods
import re
def validate_string(text):
if text.isupper() and re.match(r'^[A-Z0-9\s]+$', text):
return "The string is valid and all uppercase."
else:
return "The string is invalid or not all uppercase."
# Test cases
print(validate_string("NEW YORK 2024"))
print(validate_string("New York 2024"))
print(validate_string("NEW YORK!"))Output:
The string is valid and all uppercase.
The string is invalid or not all uppercase.
The string is invalid or not all uppercase.Read How to Reverse a String in Python?
Conclusion
In this tutorial, I have explained how to check if a string is all uppercase in Python. I explained isupper() method which is used in simple conditions, For more complex scenarios, you can use character iteration or regular expressions. I also discussed applications and some common issues and best practices.
You may also like to read:
- How to Write a List to a File in Python?
- How to Iterate Through a List in Python?
- How to Convert String to List in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.