Python

Python string lowercase

The lower() function is utilized for string handling. This function passed no parameters. It returns the string with lowercase characters. It converts all the uppercase elements of the string to lowercase elements. If we have a string with no uppercase character, the print statement returns the real string. The lower() don’t change the symbols and numbers in the string. We also determine whether the strings are identical or not by utilizing the lower() function to the strings. Similarly, we also change lowercase characters to uppercase characters. In this article, we will discuss the lower() function in Python with the help of different instances.

Converting uppercase characters to lowercase:

In this example, we take the string “VISUAL PROGRAMMING”. For this purpose, we apply the lower() function.

For the execution of Python code, we installed spyder5. We created a new project for code by tapping the “new file” option from the menu bar. The name of the new file is “temp.py5”.

The lower() function has no parameters. This function changes all the uppercase characters of the string to lowercase. For running the code, we pressed F5 from the keyboard.

The print statement returns “visual programming” by converting the original “VISUAL PROGRAMMING” to a lower case.

Converting the string having alphanumeric characters:

In this instance, we take two strings. The first one is “I LOVE TO TRAVEL DIFFERENT PLACES!”. This string contains all the elements in uppercase. The second string is “I L0v3 t0 TraV3L DIFf3R3nT PlaC3S”. This string has some numeric values, some uppercase characters, and some lowercase characters also. For this purpose, we apply the lower() function on both strings.

The lower() function changes all the characters which are in uppercase to lowercase. This function has no parameters. As the elements of the first string are in uppercase, so it is changed into lowercase. But the second string has some numeric values which are not changed by the lower() function. Only the characters of the second string are changed, which are present in uppercase.

The lower() function only converts the characters which are in uppercase. This function doesn’t change the numerical values to lower case. So the print statement of the first string returns, “i love to travel different places!”. All the characters are now lowercase. But the print statement of the second string returns “i l0v3 t0 trav3l diff3r3nt plac3s!”. The numerical values of the string are not changed to lowercase; just some characters that are in uppercase are converted into lowercase.

Converting the string having “ß” character:

In this code, we take two strings. Both strings are the same “ßAdminToN”. The string also has the German lowercase character “ß”, some uppercase characters, and some lowercase characters. Here we want these strings in lowercase. We apply the lower() function in this instance.

The German character “ß” which is present in both strings, is equal to “ss”. The lower() function couldn’t change this German character to “ss” which is already in lowercase. So for this conversion, we apply here another function which is casefold(). This function converts the German character “ß” to “ss”.

The casefold() function is applied to the first string; it changes the “ß” to “ss”, and also it converts the uppercase character to lowercase. The print statement of the first string returns “ssadminton”. This function doesn’t change the “ß” to “ss”. The print statement of the second string returns “ßadminton”.

Check whether the strings are the same or not:

Two strings are taken in the code. The first string (string1) is “I LOVE TO TRAVEL DIFFERENT PLACES!”. This string contains all the elements in the uppercase. The second string is “I L0v3 t0 TraV3L DIFf3R3nT PlaC3S”. This string is represented by string2. We change the uppercase characters of both strings to the lower case. For this purpose, we apply the lower() function on both strings.

We also apply the if-else condition here to check whether the lowercase characters of both the strings are the same or not. This function has no parameters. As the elements of the first string are in uppercase, so it is changed into lowercase. But the second string has some numeric values which are not changed by the lower() function. Only the uppercase characters of the second string are changed into lowercase.

The lower() function only converts the uppercase characters of the second string. This function doesn’t change the numerical values to lower case. The lowercase value of the first string is “i love to travel different places!”. All the characters are now lowercase. The lowercase value of the second string is “i l0v3 t0 trav3l diff3r3nt plac3s!”. The numerical values of the string are not changed to lowercase; just uppercase are converted into lowercase. After applying the if-else condition, the print statement returns that “The strings are not same”. As the lowercase characters of the strings are different, so we get this type of output.

Conclusion:

This article covered almost all possible ways to lowercase the string characters. We have discussed several methods to lowercase the string characters. You can utilize any one of them to get your work done.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content