Python String upper()

In Python, String upper() is an inbuilt string handling function.

  • String upper() is used to return a copy of a specified string where all case-based characters are in Uppercase.

  • The main aim of this function is to convert the string into Uppercase.

Python String upper(): Syntax

Below we have a basic syntax of String upper() in Python:

string.upper()

Python String upper(): Parameters

From the above syntax, it is clear that this function does not take any parameters.

  • If we pass any parameter to this function then it will raise an error.

Python String upper(): Basic Example

Below we have an example to show the working of String upper() function:

str="one woman army"
print(str.upper())

The output for the same is given below:


ONE WOMAN ARMY

Python String upper(): Digits and Symbols

If any string comprises digits, symbols, and letters; in that case digits and symbols will be returned as it is while letters will be converted into Uppercase. Let us see the code snippet given below:

 str1="123!!woman"
 print(str1.upper())

The Output will be:


123!!WOMAN

Python String upper(): To check if two string are same or not

In the example given below, we will check if the two given strings are equal or not with the help of upper() method. Let us see the code snippet given:

# working of upper() function 
string1 = 'This is a Best Place To LEARn Coding ONLINE'

string2 = 'this is a besT PLACE To Learn Coding'

if(string1.upper() == string2.upper()): 
	print("string1 and string2 are same") 
else: 
	print("String1 and string2 are not same") 

The Output will be:


string1 and string2 are not same

Time For Live Example!

Now let us take a look at the live example given below where upper() method is used:

Summary

In this tutorial, we saw how to convert all case-based characters of a string into an uppercase using String upper() method of Python, we had also applied this method on digits and symbols to see the impact of this method on digits and symbols. We had also used Live Example for the same.