A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-string-upper/ below:

Python String upper() Method - GeeksforGeeks

Python String upper() Method

Last Updated : 26 Apr, 2025

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: Syntax of upper() method

string.upper()

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) 
Explanation 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) 
Explanation

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4