str.upper()
Returns a copy of a string with every letter turned into a capital (upper-case) letter. Digits and symbols stay the same.
str.upper()upper() turns every lower-case letter into its capital form: "hello" becomes "HELLO". Numbers, spaces and punctuation do not change.
Use it for headings and labels, country or currency codes ("eur" → "EUR"), or to compare two texts without caring about case.
It works for every alphabet, not just English, and a few letters grow: the German ß becomes SS, so the result can be longer than the original.
Return value
A new string in capital letters. The original string does not change.
Examples
1Shout a word
word = "hello"
print(word.upper())
print("Room 12b".upper())HELLO ROOM 12B
2Clean up codes typed by users
codes = ["eur", "Usd", "gbp "]
clean = [c.strip().upper() for c in codes]
print(clean)['EUR', 'USD', 'GBP']
3Compare without caring about case
answer = "Yes"
if answer.upper() == "YES":
print("Confirmed")Confirmed
4Other alphabets work too
print("αθήνα".upper())
print("straße".upper())
print(len("straße"), len("straße".upper()))ΑΘΉΝΑ STRASSE 6 7
ß has no single capital form in this rule, so it becomes two letters.
Common mistakes
Expecting upper() to change the variable
Store the result: code = code.upper().
code = "gr"
code.upper()
print(code)
code = code.upper()
print(code)gr GR
Questions people ask
How do I check if a string is all capitals?
Use text.isupper(). It returns True when there is at least one letter and all letters are capitals.
How do I capitalise only the first letter?
Use str.capitalize() for the first letter of the string, or str.title() for the first letter of every word.
upper() or casefold() for comparing?
For most text either works. str.casefold() is the most thorough choice for comparing text in any language.