Skip to content
Related Articles

Related Articles

Python String upper()
  • Last Updated : 03 Dec, 2020

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

Syntax :

string.upper()

Parameters :

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

Returns :



returns a uppercased string of the given string

CODE 1: String with only alphabetic characters




# 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

CODE 2: String with alphanumeric characters




# 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

Application: One of the common application of upper() method is to check if the two strings are same or not




# 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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :