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 Representation
Example 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 Characters
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

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.