Python String upper()
Method
The upper() method in Python converts all lowercase characters in a string to uppercase. It is a built-in string method and is very useful when you want to standardize or compare text.
Syntax
string.upper()
Parameters:
- This method takes no parameters.
Returns:
- A new string with all characters in uppercase.
Example 1: Basic Usage
text = "hello world"
print(text.upper())
HELLO WORLD
Example 2: Mixed Case String
name = "Alice123"
print(name.upper())
ALICE123
Note: Numbers and symbols remain unchanged.
Use Cases
- To standardize user input (e.g., emails, usernames)
- For case-insensitive string comparisons
- To make output visually distinct (e.g., titles, warnings)
Does it change the original string?
No. Strings in Python are immutable. upper()
returns a new string — it does not modify the original.
word = "python"
new_word = word.upper()
print(word) # python
print(new_word) # PYTHON
Common Mistakes
- Trying to use
upper
without parentheses – remember it’s a method:string.upper()
- Assuming it changes the original string – you must assign the result if needed
Interview Tip
In coding tests, upper()
is handy for making string comparisons or normalizing data without worrying about the input case.
Summary
upper()
converts all characters in a string to uppercase.- Does not affect numbers or special characters.
- Returns a new string – original remains unchanged.
Practice Problem
Write a program that asks the user to enter their name and prints it in all capital letters.
name = input("Enter your name: ")
print("Your name in uppercase is:", name.upper())