str.isupper()

Check that a string is entirely uppercase — but only among characters that have a case.

String methodPython 1.0+Live demo
Common call
if code.isupper():
Returns
True or False
Replaces
`s == s.upper()` — but isupper needs at least ONE cased character
Watch out
not isupper() != islower(); digits-only string returns False
str.isupper()
bool

Demo

Live evaluation
Try:
Inputs
stringstrthe string to test
Output
'HELLO'.isupper()
True

isupper() returns True only when the string contains at least one CASED character AND every cased character is uppercase. Non-cased characters (digits, spaces, punctuation, non-cased scripts) are IGNORED — they neither pass nor fail the check. A string with ONLY digits or ONLY punctuation returns False because there is no cased character to check.

Common patterns

Validate an all-caps code
Quick check that user input matches an all-caps convention.
if not code.isupper():
    raise ValueError("code must be uppercase")
Not the same as `s == s.upper()`
The upper() equality includes digits and symbols; isupper() requires a cased character.
has_upper_intent = s.isupper()          # False for "123"
reads_as_upper   = s == s.upper()        # True  for "123"
Skip already-uppercase strings
Avoid redundant work in transformation pipelines.
if not text.isupper():
    text = text.upper()

Examples

1. All upper
"HELLO".isupper()
Returns
True
2. Mixed case
"Hello".isupper()
Returns
False
3. All lower
"hello".isupper()
Returns
False
4. Upper + digits
"HELLO123".isupper()
Returns
True # digits are non-cased
5. Upper + spaces
"HELLO WORLD".isupper()
Returns
True
6. Digits only
"12345".isupper()
Returns
False # no cased char
7. Unicode
"CAFÉ".isupper()
Returns
True
8. Empty is False
"".isupper()
Returns
False

Pitfalls

1. Requires at least one cased character
A string with only digits or only punctuation returns False — there is no cased character to verify. Same rule as islower(); different rule than the is* family that just checks emptiness.
Digits-only False
"12345".isupper()
False
Combined test
s == s.upper() and any(c.isalpha() for c in s)
True on "12345"? Depends on intent
2. not isupper() is NOT islower()
Because isupper() and islower() both require at least one cased character AND checking their case. A mixed-case string returns False from both. Do not treat them as complements.
Assumed complement
"Hello".isupper() or "Hello".islower()
False # neither, not both
Explicit
not any(c.islower() for c in s) # a subtly different check
3. Empty string returns False, not True
Same rule across the is* family — empty is always False. Ignoring the "at least one" requirement gives you a bug that manifests only on edge cases.
Wrong expectation
"".isupper()
False
Guard first
s and s.isupper()
covers the empty case
4. Non-cased scripts confuse the intent
CJK ideographs, digits, punctuation — none are cased. A string of only Chinese characters returns False from isupper(), which is often surprising.
CJK is False
"漢字".isupper()
False # not cased
Check for cased first
any(c.isalpha() for c in s)
guards against non-cased scripts

When to use

Use it
  • Validating an all-caps code, ID, or convention
  • Skipping redundant .upper() calls in transformation pipelines
  • Composing with islower / isalpha / isdigit for finer case checks
  • Testing an environment variable or acronym for proper form
Reach for something else
  • `s == s.upper()` is subtly different — chooses when digits should pass
  • Case-insensitive comparison → str.casefold
  • Titlecase check → str.istitle
  • Value has non-Latin scripts and case matters → normalize first

Notes

Complexity
O(n) — one linear scan
Return
bool — True or False
CPython impl
Objects/unicodeobject.c :: unicode_isupper
Memory
No allocation
Thread-safe
Yes — strings are immutable

FAQ

Because digits are not cased characters. isupper() requires at least one cased character AND every cased character to be uppercase. With no cased characters, the "at least one" condition fails.

History

1.0
isupper() has been part of str since Python 1.0.
3.0
Full Unicode support — checks per Unicode general category and case mapping.