isupper() returns True when the string has at least one letter and every letter is upper case. Digits, spaces, underscores, and punctuation have no case, so they are ignored: "MAX_SIZE 10!" is upper case.
A string with no letters, such as "123" or "", returns False. One lower case letter anywhere makes the result False.
text.isupper() is a method of the built-in str type: call it on a string with dot notation. No import is needed, and it never changes the original string.
Syntax
Call it on any string. There are no arguments, but the parentheses are required.
python
ok = text.isupper()
Call
What it does
"HELLO 123".isupper()
Returns True. Every letter is a capital, and the digits are ignored.
"Hello".isupper()
Returns False. The letters ello are lower case.
"123".isupper()
Returns False. There is no letter, so nothing is upper case.
The opposite check is islower(). To convert instead of test, use upper().
Library declarations
python
str.isupper() -> bool
# returns: True if there is at least one cased letter and all are upper case
# an empty string returns False
Parameters
This method takes no arguments. It always checks the whole string.
Return Value
Return Value
Description
bool
True if the string has at least one letter and all of its letters are upper case, otherwise False.
Python Examples
Example 1 — Is This Text Upper Case?
Run the check on mixed text, a number, and an empty string.
python
for text in ["PYTHON", "Python", "PYTHON 3.12!", "2024", ""]:
print(repr(text), text.isupper())
All capitals."PYTHON" is upper case, so the result is True.
One small letter is enough."Python" has lower case letters after the first one, so it is False.
Digits are ignored."PYTHON 3.12!" passes, because the digits, dot, and space have no case.
No letters, no upper case. The number and the empty string both return False.
Example 2 — Spot Messages Written in Capitals
Count how many chat messages are written entirely in capitals.
python
chat = ["hello team", "URGENT: CALL NOW", "ok", "ASAP", "see you at 5"]
loud = [msg for msg in chat if msg.isupper()]
print(loud)
print(len(loud), "of", len(chat))
Output
['URGENT: CALL NOW', 'ASAP']
2 of 5
How It Works
A filter. A message is kept when msg.isupper() is True.
Punctuation is ignored. The colon and spaces in URGENT: CALL NOW have no case, so the message still counts.
Report the count. Two of the five messages are written in capitals.
Example 3 — Check Constant Naming
Constants in Python are written in capitals, so the check can find names that break the habit.
python
names = ["MAX_SIZE", "max_size", "Max_Size", "PI", "E2"]
constants = [n for n in names if n.isupper()]
others = [n for n in names if not n.isupper()]
print(constants)
print(others)
Output
['MAX_SIZE', 'PI', 'E2']
['max_size', 'Max_Size']
How It Works
Underscores are ignored.MAX_SIZE passes, because the underscore has no case and the letters are all capitals.
Digits are ignored too.E2 has one capital letter and a digit, so it counts.
Split into two lists.not n.isupper() collects the names that are lower case or mixed.
Frequently Asked Questions
It returns True if the string has at least one letter and every letter is upper case. Digits, spaces, and punctuation are ignored.
False. The string needs at least one letter to count as upper case.
Yes. They have no case, so "MAX_SIZE_2" is upper case, while "2024" has no letters and gives False.
No. A string such as "Hello" or "123" is neither upper case nor lower case, so both checks return False for it.
Call upper(), for example text = text.upper(). It returns a new string with every letter converted to a capital.