Skip to main content

upper()

The upper() method is a string method in Python that converts all characters in a string to uppercase. It returns a new string with all characters converted to uppercase.

Parameter Values

This function does not accept any parameters.

Return Values

The upper() method returns a new string with all uppercase characters.

How to Use upper() in Python

Example 1:

The upper() method returns a copy of the string in uppercase.

string = 'hello world'
print(string.upper())
Example 2:

It does not modify the original string, but creates a new one with all letters converted to uppercase.

text = 'Python is amazing'
upper_text = text.upper()
print(upper_text)
Example 3:

It is useful when case-insensitive comparisons or searches need to be performed.

input_string = input('Enter a word: ')
if input_string.upper() == 'PYTHON':
    print('You entered Python!')