Python String upper()
Python String upper() is used to convert characters in given string into uppercase. upper() method returns a new string with the characters of this string converted to uppercase.
In this tutorial, we will learn the syntax and examples for upper() method of String class.
Syntax
The syntax to call upper() method on string x
in Python is
x.upper()
Examples
In the following program, we take a string 'Hello World'
, and convert this string into uppercase using upper() method.
Example.py
x = 'Hello World'
result = x.upper()
print('Original String : ', x)
print('Uppercase String : ', result)
Output
Original String : Hello World
Uppercase String : HELLO WORLD
If there are no uppercase letters in this string, the returned string is same as the given string.
In the following program, we take a string 'HELLO WORLD'
, and convert this string into uppercase using upper() method. Since, there are no lowercase letters in this string to convert to uppercase, the returned string should be same as that of original string.
Example.py
x = 'HELLO WORLD'
result = x.upper()
print('Original String : ', x)
print('Uppercase String : ', result)
Output
Original String : HELLO WORLD
Uppercase String : HELLO WORLD
Conclusion
In this Python Tutorial, we learned how to convert a string to uppercase using upper() method, with examples.