str.upper()

str.upper()
Returns: str · Added in v3.x · Updated March 14, 2026 · String Methods
string methods case

The .upper() method returns a copy of the string with all characters converted to uppercase. This is useful for normalizing text input, creating case-insensitive comparisons, or formatting output.

Syntax

str.upper()

Parameters

None. This method takes no parameters.

Return Value

TypeDescription
strA new string with all characters converted to uppercase

Examples

Basic usage

text = "hello"
print(text.upper())  # HELLO

text = "Hello World"
print(text.upper())  # HELLO WORLD

With numbers and symbols

# Numbers and symbols are unchanged
print("hello123!".upper())  # HELLO123!

# Email addresses
print("user@example.com".upper())  # USER@EXAMPLE.COM

Practical use case

def normalize_input(user_input):
    """Normalize user input to uppercase for comparison."""
    return user_input.upper()

# Case-insensitive matching
answer = normalize_input("yes")
if answer == "YES":
    print("User confirmed!")

Chaining with other methods

# Often used with strip() to clean input
name = "  john doe  ".strip().upper()
print(name)  # JOHN DOE

# Combined with split() for word boundaries
words = "hello world".upper().split()
print(words)  # ["HELLO", "WORLD"]

How It Works

The .upper() method only affects alphabetic characters. It converts lowercase letters (a-z) to their uppercase equivalents (A-Z). Numbers, symbols, spaces, and already-uppercase letters remain unchanged.

# Letters are converted
print("abc".upper())  # ABC

# Already uppercase letters stay the same
print("ABC".upper())  # ABC

# Non-alphabetic characters are untouched
print("a1b2".upper())  # A1B2

Common Mistakes

A common misconception is that .upper() modifies the original string. Strings in Python are immutable, so .upper() always returns a new string:

text = "hello"
text.upper()  # Returns "HELLO" but does not change text
print(text)    # Still "hello"

# You need to assign the result
text = text.upper()
print(text)    # Now "HELLO"

Unicode Considerations

The .upper() method follows Unicode rules for case conversion:

# Works with various scripts
print("café".upper())  # CAFÉ
print("über".upper())  # ÜBER

# The German sharp s becomes SS
print("ß".upper())  # SS

Performance Notes

Calling .upper() creates a new string and requires iterating through all characters. For very large strings, this has a time complexity of O(n) where n is the string length. The memory usage is also O(n) since a new string is created.

import time

# Benchmarking .upper() on a large string
large_text = "hello world " * 100000

start = time.perf_counter()
result = large_text.upper()
elapsed = time.perf_counter() - start

print(f"Uppercased 1.3M characters in {elapsed:.4f} seconds")

See Also