Python String upper
Now, we are going to learn about the upper method. As the name of the method suggests, the upper method returns the copy of the string, with all the alphabets from the string in uppercase. So, whenever we are required to have our string in uppercase, we can make use of the upper method. Remember that it returns a new string, with the alphabet converted to uppercase. Let’s have a look at a simple example, which demonstrates the same thing.
Python String upper() Method
As you can see in the above program, we have a string, and then we are trying to call the upper method. This method returns a string, with the alphabet converted to uppercase. After that, we are printing the original string, as well as the converted string. Let’s have a look at the output now.
The original string: gyanipandit
The string in the uppercase: GYANIPANDIT
As you can see, we got the string converted in uppercase in the output. The original string is as it was. So, whenever we want to have our string in uppercase, we can make use of the upper method. Let’s have a look at another program, through which, we would get a clearer idea about the upper method.
As you can see in the above program, we again have a string, but this time, we have some alphabets which are already in uppercase. Let’s have a look at the output now.
The original string: GyaniPANDIT
The string in the uppercase: GYANIPANDIT
As you can see, this time as well, we got the string in the uppercase, and the original string is as it was. Also, Let’s have a look at another example, in which, we have some characters other than alphabets. Let’s have a look at the below program.
As you can see in the above program, we again have a string, but this time, in the string, we have some numbers as well. Let’s have a look at the output now, so as to get a clearer picture.
The original string: GyaniPandit123
The string in the uppercase: GYANIPANDIT123
As you can see, even if we had the numbers in the string, all the alphabets were converted to uppercase.
So, as and when required, we can make use of the upper method in our python programs, so as to get a string, in which all the alphabets are in the uppercase. Remember that the upper method returns a string, with the alphabet converted in uppercase. The original string is as it was.