Python String upper() Method

Short answer
text.upper() returns a new string with every lowercase letter converted to uppercase; digits, spaces and symbols stay the same.

Use upper() to display codes, headings or warnings in capitals, or to put two strings into the same case before you compare them. It takes no arguments and, like all string methods, does not modify the original string.

For the reverse operation see lower(). For case-insensitive comparison, lower() or casefold() is the usual choice.

Quick facts
Syntaxtext.upper()
ParametersNone
ReturnsA new str with cased characters in uppercase
Time complexityO(n) in the length of the string

How upper() converts letters to uppercase

Python walks through the characters and maps each lowercase letter to its uppercase form. Characters without case, such as digits, spaces and punctuation, are copied unchanged. The mapping follows Unicode rules, so accented letters also work, and a few letters expand: the German ß becomes SS.

Python
print("order #42 shipped".upper())
print("stra\u00dfe".upper())
print("caf\u00e9".upper())

upper() vs isupper() and the other case methods

upper() makes a new string; isupper() only asks whether the letters are all uppercase and returns True or False. The other case methods are listed below.

Python
code = "ab12"
print(code.isupper())
print(code.upper().isupper())

Case conversion methods compared

MethodWhat it doesResult for "hello World"
upper()All letters uppercase'HELLO WORLD'
lower()All letters lowercase'hello world'
title()First letter of each word uppercase'Hello World'
capitalize()First character uppercase, the rest lowercase'Hello world'
swapcase()Upper becomes lower and the reverse'HELLO wORLD'
casefold()Aggressive lowercase for comparisons'hello world'

Common uses: codes, constants and comparisons

Product codes, country codes and state abbreviations are normally stored in uppercase, so apply upper() when saving user input. When comparing text without caring about case, convert both sides: a.upper() == b.upper(). See comparing strings ignoring case for the recommended approach.

Examples you can run

Press Run, then edit the code and run it again.

Convert a message to uppercase

Only letters change.

Convert a message to uppercase
note = "low stock: item 7"
print(note.upper())
Expected outputLOW STOCK: ITEM 7

Normalise a code typed by a user

Strip spaces, then uppercase so any typing style matches.

Normalise a code typed by a user
typed = "  ab-204 "
code = typed.strip().upper()
print(code)
print(code == "AB-204")
Expected outputAB-204
True

Uppercase each name in a list

Use a list comprehension to apply upper() to every item.

Uppercase each name in a list
names = ["asha", "ravi", "meena"]
print([n.upper() for n in names])
Expected output['ASHA', 'RAVI', 'MEENA']

Common mistakes

Expecting upper() to modify the variable

✗ Wrong

city = "pune"
city.upper()
print(city)
pune (unchanged)

✓ Right

city = "pune"
city = city.upper()
print(city)

Assign the returned string.

Forgetting the parentheses

✗ Wrong

word = "hi"
print(word.upper)
<built-in method upper of str object at 0x...> (the method itself, not the result)

✓ Right

word = "hi"
print(word.upper())

Call the method with ().

Calling upper() on a number

✗ Wrong

age = 25
print(age.upper())
AttributeError: 'int' object has no attribute 'upper'

✓ Right

age = 25
print(str(age).upper())

upper() exists only on strings; convert first if needed.

Python String upper() Method: questions people ask

How do I convert a string to uppercase in Python?

Call text.upper(), which returns a new string with all letters in capitals.

How do I check if a string is uppercase in Python?

Use text.isupper(), which returns True only if the string has at least one cased letter and all cased letters are uppercase.

Does upper() change numbers or symbols?

No. Characters that have no uppercase form are left exactly as they are.

Keep learning

Step-by-step lessons:
Python StringsPython String Methods

Related:
Python String lower() MethodPython String title() MethodPython String capitalize() MethodPython String swapcase() MethodHow to Compare Strings Ignoring Case in Python

More in string methods:
Python String split() MethodPython String join() MethodPython String strip() MethodPython String lstrip() MethodPython String rstrip() MethodPython String replace() MethodPython String lower() MethodPython String title() Method See all →