String method

str.upper()

Returns a copy of a string with every letter turned into a capital (upper-case) letter. Digits and symbols stay the same.

BeginnerEvery example below runs in your browser. Change the code and press Run.

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

Pythoneditable
word = "hello"
print(word.upper())
print("Room 12b".upper())
Output
HELLO
ROOM 12B

2Clean up codes typed by users

Pythoneditable
codes = ["eur", "Usd", "gbp "]
clean = [c.strip().upper() for c in codes]
print(clean)
Output
['EUR', 'USD', 'GBP']

3Compare without caring about case

Pythoneditable
answer = "Yes"
if answer.upper() == "YES":
    print("Confirmed")
Output
Confirmed

4Other alphabets work too

Pythoneditable
print("αθήνα".upper())
print("straße".upper())
print(len("straße"), len("straße".upper()))
Output
ΑΘΉΝΑ
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().

Pythoneditable
code = "gr"
code.upper()
print(code)
code = code.upper()
print(code)
Output
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.

Spotted a mistake on this page? Tell us