Python String upper()


Python String upper() method

Python String upper() method is used to convert all the cased characters in the string to upper case.

Consider that given string is in x.

x = "Hello World!"

Then the return value of x.upper() is

"HELLO WORLD!"

In this tutorial, you will learn the syntax and usage of String upper() method in Python language.

Syntax of upper() method

The syntax of String upper() method in Python is given below.

str.upper()

The upper() method takes no parameters.

upper() method returns a new string value created by converting the cased characters in the given string to upper case.

Examples

1. upper() - Convert given Python string to upper case

In the following program, we take a string in variable x. We have to covert this string to upper case.

Call upper() method on the string x and store the returned value in x_upper.

Python Program

x = "Hello World!"

x_upper = x.upper()

print(f"Given string : {x}")
print(f"Upper string : {x_upper}")

Output

Given string : Hello World!
Upper string : HELLO WORLD!

Summary

In this tutorial of Python String Methods, we learned about String upper() method, its syntax, and examples.