Python String upper()

The string upper() method converts all lowercase characters in a string into uppercase characters and returns it.

The syntax of upper() method is:

string.upper()

String upper() Parameters()

The upper() method doesn't take any parameters.


Return value from String upper()

The upper() method returns the uppercased string from the given string. It converts all lowecase characters to uppercase.

If no lowercase characters exist, it returns the original string.


Example 1: Convert a string to uppercase

# example string
string = "this should be uppercase!"
print(string.upper())

# string with numbers
# all alphabets whould be lowercase
string = "Th!s Sh0uLd B3 uPp3rCas3!"
print(string.upper())

When you run the program, the output will be:

THIS SHOULD BE UPPERCASE!
TH!S SH0ULD B3 UPP3RCAS3!

Example 2: How upper() is used in a program?

# first string
firstString = "python is awesome!"

# second string
secondString = "PyThOn Is AwEsOmE!"

if(firstString.upper() == secondString.upper()):
    print("The strings are same.")
else:
    print("The strings are not same.")

When you run the program, the output will be:

The strings are same.

Note: If you want to convert to lowercase string, use lower(). You can also use swapcase() to swap between lowercase to uppercase.