Python String upper() Method
The Python string upper() method returns a new string with lowercase letters changed to uppercase.
This page explains what upper() does, how to use it, what it returns, and a few common beginner mistakes. It stays focused on the method itself.
Quick example
text = "Hello World"
result = text.upper()
print(result)
# HELLO WORLD
upper() returns a new string with letters changed to uppercase. It does not change the original string in place.
What upper() does
upper()returns a copy of a string with lowercase letters converted to uppercase- It works on string values only
- It returns a new string
- The original string stays unchanged
If you are new to strings, see what a string is in Python or Python strings explained: basics and examples.
Basic syntax
The syntax is:
string.upper()
Important points:
- It takes no arguments
- You call it on a string variable or string literal
- It returns the uppercase version of the string
Example with a variable:
name = "python"
print(name.upper())
Example with a string literal:
print("hello".upper())
Simple example
Here is a basic example that converts a lowercase word to uppercase and stores the result in a new variable:
word = "banana"
uppercase_word = word.upper()
print(word)
print(uppercase_word)
Output:
banana
BANANA
What this shows:
wordkeeps its original valueuppercase_wordstores the returned value fromupper()
upper() does not change the original string
Strings are immutable in Python. That means you cannot change the characters inside a string directly.
So this method:
name = "alice"
name.upper()
print(name)
Output:
alice
Even though upper() was called, name did not change because the result was not saved.
If you want to keep the uppercase version, assign it back to the variable:
name = "alice"
name = name.upper()
print(name)
Output:
ALICE
This is one of the most common beginner mistakes with string methods.
What happens to numbers, spaces, and symbols
upper() only changes letters that have uppercase forms.
- Numbers stay the same
- Spaces stay the same
- Punctuation stays the same
- Only letters are changed
Example:
text = "Room 7, table #3!"
print(text.upper())
Output:
ROOM 7, TABLE #3!
The letters changed to uppercase, but the number, space, comma, and symbol stayed the same.
When to use upper()
upper() is useful when you want to standardize text.
Common uses:
- Standardize user input for comparisons
- Format labels or headings
- Make text easier to compare in simple cases
Example: simple comparison
answer = "yes"
if answer.upper() == "YES":
print("Matched")
Output:
Matched
This can help when users type different letter cases, such as yes, Yes, or YES.
Common mistakes
Forgetting to save the returned value
A very common mistake is expecting text.upper() to change the original variable automatically.
Wrong:
text = "hello"
text.upper()
print(text)
Output:
hello
Correct:
text = "hello"
text = text.upper()
print(text)
Output:
HELLO
Trying to call upper() on a non-string value
upper() is a string method. If the value is not a string, it will fail.
Example:
number = 123
print(number.upper())
This causes an error because int objects do not have an upper() method.
If needed, convert the value to a string first:
number = 123
print(str(number).upper())
Output:
123
Confusing upper() with title case
upper() makes all letters uppercase. It does not make every word start with a capital letter.
text = "hello world"
print(text.upper())
Output:
HELLO WORLD
If your goal is different, another method may fit better. For example, lower() makes text lowercase, and replace() changes parts of a string.
Related string methods
These string methods are often used with upper():
lower()for lowercase textstrip()for removing leading and trailing whitespacereplace()for changing parts of a stringstartswith()andendswith()for checks
Example:
text = " hello world "
cleaned = text.strip()
loud = cleaned.upper()
print(loud)
Output:
HELLO WORLD
FAQ
Does upper() change the original string?
No. It returns a new uppercase string. Save the result if you want to keep it.
Does upper() take any arguments?
No. The method is called with empty parentheses: text.upper().
What happens to numbers and symbols?
They stay the same. upper() only changes letters that can be converted to uppercase.
Can I use upper() for case-insensitive comparison?
Yes, for simple cases. Convert both strings before comparing them.
Example:
a = "python"
b = "PYTHON"
print(a.upper() == b.upper())
Output:
True