Python String upper() Method

Python String upper() method is used to convert all characters in a string into uppercase characters and returns it.

This method doesn’t modify the original string. Instead, it returns a new string.

Syntax

string.upper()

Parameters

This method doesn’t take any parameters.

Return Value

It returns a new string where all the characters are in uppercase. If no lowercase characters exist, it returns an original string.

Visual RepresentationVisual Representation of How to Use String Upper Method in PythonExample 1: How to Use String upper Method

string = "expecto patronum"
print("Original String:", string)

upper_case = string.upper()
print("Uppercase String:", upper_case)

Output

Original String: expecto patronum

Lowercase String: EXPECTO PATRONUM

Example 2: String with Alphanumeric CharactersVisual Representation of String with Alphanumeric Characters (Python String Upper)

string = "mlm20 mlm30" 

print("Original String:", string) 

upper_case = string.upper() 

print("Uppercase String:", upper_case)

Output

Original String: mlm20 mlm30

Lowercase String: MLM20 MLM30

Example 3: Comparison of strings using the upper() method

str1 = "MLM20 MLM30"
str2 = "mlm20 mlm30"

if (str1.upper() == str2.upper()):
 print("Strings are same")
else:
 print("Strings are not same")

Output

Strings are same

 

Python String lower()

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.