Python String upper Method

The Python upper method transforms all characters in a string to uppercase and returns the modified string in uppercase format.

Signature

Example

upper()

Parameters

No parameters

Return

It returns a string.

Let us examine a few examples of the upper method to grasp its functionality.

Python String upper Method Example 1

To begin, let's examine a straightforward illustration of the upper method. This particular method yields a string where all characters have been converted to uppercase.

Example

# Python upper() method
# Declaring table and variables
str = "Hello logicpractice"
# Calling function
str2 = str.upper()
# Displaying result
print(str2)

Output:

Output

HELLO LOGICPRACTICE

Python String upper Method Example 2

Let's explore how we can implement this technique in programming. The following example demonstrates the conversion of every element within the list to uppercase. Observe the example provided.

Example

# Python upper() method
# Declaring variables
list = ["irfan","sohan","mohan"]
for  l in list:
    print(l.upper()) # Displaying result

Output:

Output

IRFAN
SOHAN
MOHAN

Python String upper Method Example 3

Here is an illustration that transforms every string that begins with a vowel into uppercase. Refer to the example provided below.

Example

# Python upper() method
# Declaring variables
names = ["irfan","sohan","aman","mohan"]
vowels = ['a','e','i','o','u']
for  l in names:
    for v in vowels:
        if(l.startswith(v)):
            print(l.upper()) # Displaying result

Output:

Output

IRFAN
AMAN

Input Required

This code uses input(). Please provide values below: