Python String upper()

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

upper() Syntax

The syntax of upper() method is:


upper() Parameter

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

upper() 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 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

Get notified of the best deals on our WordPress themes.

You May Also Like
List of Python free ebooks

List of Free Python Books

Table of Contents Hide Python SuccinctlyPython Data Science HandbookThink Python 2nd EditionAutomate the Boring Stuff with PythonMaking Games with Python & PygameData Structures and Algorithms in Python Google Python Style GuideA…
View Post