Python String lower
Now, we are going to learn about the lower method. As the name of the method says, the lower method returns a copy of the string, with the alphabet converted to lowercase. So, whenever we are required to convert the string into lowercase, we can make use of the lower method. Remember that the method returns a new string, and the original string is left as it was. Let’s have a look at a simple program, which demonstrates the same thing.
Python String lower() Method
As you can see in the above program, we have a string, in which all the alphabets here are in uppercase. Then we are calling the lower method. This method returns a string, which is assigned to the string2 variable. Then, we printed both strings here. Let’s have a look at the output now.
The original string: GYANIPANDIT
The string in the uppercase: gyanipandit
As you can see in the output, we have the original string as it was, and then there is a string, in which, the alphabets are converted in lowercase. So, we have got the lowercase string for our string using the lowercase method.
Let’s have a look at another example, with which, we would get a clearer picture of the lower method.
As you can see in the above program, we have a string, and this time, some of the alphabets are already in lowercase, and some are in uppercase. Then we are again calling the lower method on the string. Again, the lower method returns a string, with the alphabet converted to lowercase. Let’s have a look at the output once.
The original string: gyaniPANDIT
The string in the uppercase: gyanipandit
As you can see in the above output, the original string was left as it was, and the lower returned the string, with alphabets converted to lowercase.
Now, Let’s consider a case, where we have a string, where not all the characters are alphabets. Let’s have a look at the below program, in which, such a situation is being described.
As you can see in the above program, we have a string, in which, all the characters are not alphabets. Then, we are calling the lower method. So, even if there are some characters that are not alphabets, we have the string returned from the lower method, with all the alphabets converted to the lowercase. Let’s have a look at the output now.
The original string: GYANIPANDIT123
The string in the uppercase: gyanipandit123
As you can see in the output, we got the string, with all the alphabets converted to lowercase. So, as and when required, we can make use of the lower method, using which, we get the string, with all the alphabets converted to the lowercase. Remember that the lower method returns a string, and the original string is as it was.