To convert a string to uppercase in Python, you can use the upper()
method of the String class.
In this example,
"Hello World"
to the variable str1
.upper()
method to convert it to uppercase and store the result in the variable upperCaseStr1
.upper()
method returns a new string with all characters converted to uppercase.upperCaseStr1
.str1 = "Hello World"
upperCaseStr1 = str1.upper()
print("Uppercase of given string is:", upperCaseStr1)
Uppercase of given string is: HELLO WORLD
In this example,
"apple"
to the variable str2
.upper()
method to convert it to uppercase and store the result in the variable upperCaseStr2
.upper()
method returns a new string with all characters converted to uppercase.upperCaseStr2
.str2 = "apple"
upperCaseStr2 = str2.upper()
print("Uppercase of given string is:", upperCaseStr2)
Uppercase of given string is: APPLE
In this tutorial, we learned How to convert String to Uppercase in Python language with well detailed examples.