Tutorial Study Image

Python upper()

The upper() function in python helps to return a copy of the original string, in which all the lowercase characters of the string are converted into uppercase. If no lowercase letters, it will return the original string.


string.upper() 
 

upper() Parameters:

The upper() method doesn't take any parameters. At the time of conversion, all symbols and letters are ignored.

upper() Return Value

The return value is always a string. This method is similar to capitalize() method, the difference is that capitalize() convert only the first letter of the word into uppercase whereas upper() converts all characters of the string into uppercase.

Input Return Value
string uppercased string

Examples of upper() method in Python

Example 1: How to convert a string to uppercase


# example string
string = "How are you?"
print(string.upper())

# string with numbers

string = "Hii! How Are You123?"
print(string.lower())
 

Output:


HOW ARE YOU?
HII! HOW ARE YOU123?

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


# first string
String1 = "ProgRammIng LanGuaGe!"

# second string
String2 = "programming language!"

if(String1.upper() == String2.upper()):
    print("The two strings are same.")
else:
    print("The two strings are not same.")
 

Output:


The two strings are same.