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.
This method doesn’t take any parameters.
It returns a new string where all the characters are in uppercase. If no lowercase characters exist, it returns an original string.
Visual RepresentationExample 1: How to Use String upper Method
string = "expecto patronum" print("Original String:", string) upper_case = string.upper() print("Uppercase String:", upper_case)
Original String: expecto patronum Lowercase String: EXPECTO PATRONUM
Example 2: String with Alphanumeric Characters
string = "mlm20 mlm30" print("Original String:", string) upper_case = string.upper() print("Uppercase String:", upper_case)
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")
Strings are same