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 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.
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.
The output is like below.
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.
The output will be like below.