str.upper()
Uppercase every cased character — the mirror of str.lower.
Common call
"hello".upper()
Returns
new str — original unchanged
Replaces
digits and punctuation pass through untouched
Watch out
German ß uppercases to "SS" — length can change
str.upper()
→ str
Demo
Live evaluation
Try:
Inputs
stringstrthe source
Output
'hello world'.upper()
'HELLO WORLD'
Every character with an uppercase form is converted; digits and punctuation pass through. Note the ß case — it expands to SS, so the result can be longer than the input.
Common patterns
Constants and codes
Normalize identifiers that are conventionally uppercase.
country = code.upper() # 'us' → 'US'
Emphasis in terminal output
Cheap visual weight without markup.
print(f"{level.upper()}: {message}")
Case-insensitive comparison
Works like lower() — just pick one side convention and stick to it.
if answer.upper() == "Y": proceed()
Examples
1. Basic uppercasing
"hello world".upper()
Returns
'HELLO WORLD'2. Digits and punctuation
"abc-123!".upper()
Returns
'ABC-123!'3. Unicode letters
"café".upper()
Returns
'CAFÉ'4. ß expands
"straße".upper()
Returns
'STRASSE'Pitfalls
1. The result must be assigned
Strings are immutable — upper returns a new string.
Wrong
s = "hi" s.upper() print(s)
hi
Fix
s = s.upper() print(s)
HI
2. Length can change
A few Unicode characters expand when uppercased — do not assume len is preserved.
Surprising
len("straße") == len("straße".upper())
False — 6 vs 7
Measure after
padded = s.upper().ljust(width)
pad the converted string
When to use
Use it
- Display text that must be uppercase
- Normalizing conventional codes (ISO country, currency)
- Case-insensitive comparison (pick upper or lower, be consistent)
Reach for something else
- Caseless matching of arbitrary Unicode → str.casefold
- First letter only → str.capitalize
- Word-initial capitals → str.title
Notes
Complexity
O(n)
Return
new str — source untouched
CPython impl
Objects/unicodeobject.c :: do_upper
Memory
One new string (may grow for expanding characters)
Thread-safe
Yes — str is immutable
FAQ
Use str.isupper — True when all cased characters are uppercase and at least one exists.
"ABC".isupper() # True
History
2.0
Method available on the unified string type.