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.

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
Convert A List To String In Python

Convert a list to string in Python

Table of Contents Hide Program to convert a list to string in PythonUsing join() methodUsing List ComprehensionIterating using for loopUsing map() method There are various scenarios where you would need…
View Post
Importerror No Module Named Pandas

ImportError: No module named Pandas

In Python, if you try to import pandas without installing the module using pip, you will get ImportError: no module named pandas error.  In this tutorial, let’s look at installing…
View Post
Python Remove Newline From String

Python Remove Newline From String

Table of Contents Hide Python Remove Newline From StringUsing strip() method to remove the newline character from a stringUsing replace() method to remove newlines from a stringUsing regex to remove…
View Post