The Wayback Machine - https://web.archive.org/web/20230512160711/https://www.geeksforgeeks.org/python-string-upper/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Python String upper()

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Python String upper() method converts all lowercase characters in a string into uppercase characters and returns it.

Python String upper() Syntax

Syntax: string.upper()

Parameters: The upper() method doesn’t take any parameters. 

Returns: returns an uppercased string of the given string.

String upper() in Python Example

String with only alphabetic characters

In this example, we will take only alphabet characters, both lower and upper case characters as a Python String and apply the string upper() function to it.

Python3




# Python3 program to show the
# working of upper() function
text = 'geeKs For geEkS'
 
print("Original String:")
print(text)
 
# upper() function to convert
# string to upper_case
print("\nConverted String:")
print(text.upper())

Output: 

Original String:
geeKs For geEkS

Converted String:
GEEKS FOR GEEKS

String with Alphanumeric Characters 

In this example, we will take alphanumeric characters, i.e., a mixture of alphabets and numeric values, and then apply the string upper() function in Python.

Python3




# Python3 program to show the
# working of upper() function
text = 'g3Ek5 f0r gE3K5'
 
print("Original String:")
print(text)
 
# upper() function to convert
# string to upper_case
print("\nConverted String:")
print(text.upper())

Output: 

Original String:
g3Ek5 f0r gE3K5

Converted String:
G3EK5 F0R GE3K5

Use of upper() methods used in a Python Program

One of the common applications of the upper() method is to check if the two strings are the same or not. We will take two strings with different cases, apply upper() to them, and then check if they are the same or not.

Python3




# Python3 program to show the
# working of upper() function
text1 = 'geeks fOr geeks'
 
text2 = 'gEeKS fOR GeeKs'
 
# Comparison of strings using
# upper() method
if(text1.upper() == text2.upper()):
    print("Strings are same")
else:
    print("Strings are not same")

Output: 

Strings are same

My Personal Notes arrow_drop_up
Last Updated : 09 May, 2023
Like Article
Save Article
Similar Reads
Related Tutorials