String upper() Method in Python

Python String upper() Method

In Python, the upper() method is a built-in string method used to convert all characters in a string to uppercase. It does not modify the original string but returns a new string with all the alphabetic characters converted to uppercase.

Here's the basic syntax of the upper() method:

string.upper()

Here, string is the string on which you want to apply the upper() method. The method does not take any arguments.

Let's see some examples:

# Example 1
text = "hello, world!"
uppercase_text = text.upper()
print(uppercase_text)  # Output: "HELLO, WORLD!"

# Example 2
message = "this is a Test String"
uppercase_message = message.upper()
print(uppercase_message)  # Output: "THIS IS A TEST STRING"

As you can see, all the letters in the original string are converted to uppercase in the resulting string. The upper() method is particularly useful when you want to perform case-insensitive comparisons or when you need the entire string to be in uppercase for further processing.