Python String upper() Method Tutorial

The string is an important part of Python programming. A string may contain lowercase and upper case letters. If we need to make all lowercase letters uppercase there is the upper() method. Even there are alternative ways the easiest and fast way is using the upper() method of a string type.

upper() Method Syntax

The upper() method has the following syntax. The upper() method does not take any parameter and uppercase STRING is returned.

STRING.upper()
  • STRING is the string variable, object or literal which is converted into the uppercase.

upper() Method with String Variable

The upper method can be used for a string variable or object. The execution of the upper() method returns the uppercase of the provided string variable or object.

name = "ismail"

surname = "baydan"

print(name.upper())

surname.upper()

print(surname)

The output will be like below. The surname is not uppercase because the returned uppercase value is not stored.

ISMAIL
baydan

upper() Method with String Literal

The upper() method can be also used for the string literal even without creating a variable or object. The provided string literal is returned as uppercase.

print("ismail".upper())

The output is like below.

ISMAIL

Reverse upper() Method (lower())

The uppercase letters can be returned into the lowercase by using the lower() method. This is called reversing the upper() method. The syntax is the same with the upper() method where the only difference is return value is lowercase.

print("ISMAIL".upper())

The output will be like below.

ismail

Leave a Comment