Open In App

Python String upper() Method

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

upper() method in Python is a built-in string method that converts all lowercase letters in a string to uppercase. This method is simple to use and does not modify the original string; instead, it returns a new string with the modifications applied. Example:

Python
s = "learn python with gfg!"
res = s.upper()
print(res) 

Output
LEARN PYTHON WITH GFG!

Explanation:

  • The upper() method converts all the lowercase letters to uppercase and returns a new string.
  • The original string ‘s’ remains unchanged.

Syntax of upper() method

string.upper()

Parameters:

  • The upper() method does not take any parameters.

Return Type: This method returns a new string in which all lowercase characters in the original string are converted to uppercase. If the original string has no lowercase letters then it returns the string unchanged.

Example of upper() method

1. Standardizing case for comparison

Let’s consider a scenario where we want to compare two strings without considering their case. The upper() method can help us standardize both strings to uppercase before comparison.

Python
s1 = "Python"
s2 = "PYTHON"

# Using upper() for comparison
res = s1.upper() == s2.upper()
print(res) 

Output
True

Explanation

  • The upper() method converts both s1 and s2 to uppercase.
  • The comparison s1.upper() == s2.upper() evaluates to True as both strings become “PYTHON”.

2. Handling mixed-case strings

upper() method is also very useful when we have a string with a mix of lowercase and uppercase letters, and we want to convert all characters to uppercase.

Python
# Converting mixed-case string to uppercase
s = "PyThoN is FuN"

res = s.upper()
print(res) 

Output
PYTHON IS FUN

Explanation

  • The upper() method processes the string ‘s’ and converts all lowercase letters to their uppercase equivalents.
  • Non-alphabetic characters like spaces remain unchanged.

Next Article
Practice Tags :

Similar Reads