Python String upper()

Python String upper() method is a built-in function that converts all the lowercase characters into uppercase and returns it.


The syntax of upper() method is:



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

Return Value

The upper() method returns the uppercase of a given string. It converts all the lowercase characters in a string to uppercase.

If the String does not consist of any lowercase characters, it returns the original String.

Example 1: Convert a string to uppercase

The following program converts all the lowercase characters in a string to uppercase.

# Program to convert lowercase characters to uppercase
text= "ItsMYCode Coding Simplified"
text2="hello world"
print('Original String: ',text)
print('Original String: ',text2)

print('Uppercase String: ',text.upper())
print("Uppercase String: ", text2.upper())


Original String:  ItsMYCode Coding Simplified
Original String:  hello world
Uppercase String:  HELLO WORLD

Example 2: How upper() is used in a program?

If the string contains numeric/digits, the upper() method will return as is. Only the characters with lowercase will be converted to uppercase and returned.

Note: The same logic applies to even symbols and special characters. Apart from lowercase, none of the other characters will be converted. It will be returned as-is.

# Program to convert Alphanumeric characters to uppercase
text= "Its 2:00pm ist in India"
print('Original String: ',text)
print('Uppercase String: ',text.upper())


Original String:  Its 2:00pm ist in India
Uppercase String:  ITS 2:00PM IST IN INDIA

Example 3: How to check if two strings are the same in Python

# Program to check the email and re-entered email is same or different
email= ""

if(email.upper() == confirmemail.upper()):
    print("Email Address are same")
    print("Email Address are not same")


Email Address are same
Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like
Python Slice()

Python slice()

Table of Contents Hide slice() Syntax slice() Parametersslice() Return ValueExample 1: Python slice string Get substring using slice objectExample 2: Get substring using negative indexExample 3: Python slice list or Python slice arrayExample 4: Python…
View Post