What is string.upper() in Python?

The upper method in Python converts all the characters of a string to uppercase.

Syntax

string_A.upper()

Parameter

The function takes in no parameters.

Return value

The function returns a new string that is created from string_A by converting all the characters of string_A to uppercase.

If there are no lowercase characters in string_A, then the original string is returned.

All the characters of the string are converted to uppercase

Code

string_A = "eduCativE"
print(string_A, " upper() -> ", string_A.upper())

In the code above, we create an eduCativE string and call the upper method, which converts all of the characters of the string to uppercase and returns EDUCATIVE.

string_A = "Educative"
string_B = "EDUCATIVE"
print("String_A = ", string_A)
print("String_B = ", string_B)
print("String_A == String_B ", string_A == string_B)
print("String_A.upper() == String_B.upper() ", string_A.upper() == string_B.upper())

In the code above, we create two strings, Educative and EDUCATTIVE. We get False when we compare the two strings because the cases of the strings are different.

We then use the upper method to convert both strings to uppercase. After both strings are converted to uppercase, we get True when we check whether the two strings are the same.