Python upper() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

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()
CallWhat 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 ValueDescription
strA 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.

python
note = "meeting at noon"
loud = note.upper()

print(loud)
print(note)
print(len(note), len(loud))

How It Works

  1. A new string. upper() returns "MEETING AT NOON", and loud now refers to it.
  2. The note is unchanged. Printing note still shows the lower case text.
  3. Same length here. For plain English letters, one letter becomes exactly one capital, so both lengths are 15.

Example 2 — Write Country Codes in One Style

Convert a list of codes to upper case with a list comprehension, then join them.

python
countries = ["in", "us", "De"]
codes = [name.upper() for name in countries]

print(codes)
print(", ".join(codes))

How It Works

  1. One call per item. The comprehension runs name.upper() on each text and collects the results in a new list.
  2. Mixed input, one style. "De" becomes "DE", so every code is now written the same way.
  3. Join for display. ", ".join(codes) glues the three codes into one line of text.

Example 3 — When Upper Case Is Longer

See that the German sharp s turns into two letters, and test the result with isupper().

python
word = "stra\u00dfe"
big = word.upper()

print(big)
print(len(word), len(big))
print("ready".upper().isupper())

How It Works

  1. One letter, two capitals. The escape \u00df stands for the German sharp s, and upper() writes it as SS.
  2. The length grows. The original has 6 characters and the upper case version has 7.
  3. Check the result. "ready".upper().isupper() is True, because every letter is now a capital.

Frequently Asked Questions

It returns a copy of the string with every letter converted to upper case. Digits, spaces, and punctuation are unchanged.
No. Strings are immutable, so upper() returns a new string. Assign the result, for example text = text.upper(), to keep it.
upper() converts every letter to a capital, while capitalize() makes only the first letter a capital and the rest lower case.
Yes, for a few characters. For example the German sharp s becomes SS, so a word that contains one sharp s gets one character longer.
Call isupper(), which returns True when every letter is upper case and there is at least one letter.

Next: zfill()

Return the string padded on the left with zeros to a given width, keeping a leading sign.

zfill() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful