Python String upper()

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

Syntax

The syntax of upper() method is:

string.upper()

Parameter

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

Output

Original String:  ItsMYCode Coding Simplified
Original String:  hello world
Uppercase String:  ITSMYCODE CODING SIMPLIFIED
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())

Output

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= "info@itsmycode.com"
confirmemail="INFO@ITSMYCODE.COM"

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

Output

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