upper() makes every letter in a string upper case, so "hello" becomes "HELLO". Digits, spaces, and punctuation stay as they were.
Like every string method, it returns a new string and leaves the original alone. It is handy for shouting a heading, writing codes such as country or coupon codes in one style, and comparing text without caring about case.
text.upper() is a method of the built-in str type: call it on a string with dot notation. No import is needed, and it never changes the original string.
Syntax
Call it on any string. There are no arguments, but the parentheses are required.
python
result = text.upper()
Call
What it does
"PyThOn".upper()
Returns 'PYTHON'.
"abc 123!".upper()
Returns 'ABC 123!'. Digits, spaces, and symbols are left alone.
"stra\u00dfe".upper()
Returns 'STRASSE'. The German sharp s, written \u00df in Python code, becomes two letters, so the string gets longer.
To change the other way use lower(). To capitalize only the first letter use capitalize(), and to capitalize every word use title().
Library declarations
python
str.upper() -> str
# returns: a new string; the original is unchanged
# raises: nothing (works for any string)
Parameters
upper() takes no arguments. It always works on the whole string.
Return Value
Return Value
Description
str
A new string in which every cased character is upper case. The original string is not changed, and the new string can be longer than the old one.
Python Examples
Example 1 — Shout a Message
Convert a note to capitals and look at both versions.