Introduction to Lowercase in Python
Lowercase means small letter alphabets, and uppercase refers to capital letters or alphabets. In Python, to convert any string with uppercase to lowercase using a Python built-in function or method is known as lower(). This method or function lower() returns the string in lowercase if it is in uppercase; else, it will return the same original string itself. To do the opposite of this method, an upper() function does exactly the opposite of the lower() function; it returns the capital letters from the given string, which is in lowercase and converts it into upper. The lower() function does not have any parameters or arguments. These functions in Python are used to convert the strings to upper or lower case characters or letters.
Working of Lowercase Function in Python
This article is about how to convert strings of uppercase to lowercase. In Python, as we discussed, we have a lower() function for this. The lower() function is applied to only alphabets because numbers and special characters do not have any upper or lower case. The lower() function, after converting to lowercase, creates another string other than the original string and returns that string.
This method does not have any arguments as it only returns the lowercase characters.
input_str = "THIS IS EDUCBA TRAINING PORTAL" output_str = input_str.lower() print("The lowercased characters are:", output_str)
Examples of Lowercase in Python
Following are some examples of python lowercase:
Example #1 – islower() method
In Python, there is another function called islower(); This function checks the given string if it has lowercase characters in it. If yes, then it returns true; else, if there are no lowercase characters, it returns false. This function also has no arguments. Similarly, it can be even done to check uppercase characters using the isupper() function. This function is only applicable to the alphabet, not to numbers or special characters. Let us see the syntax and example below:
There are no parameters for this function also. But it returns the Boolean value that is either true when there are lowercase characters present in the given string or false when no lowercase characters are there in the given string.
Let us now take an example to show how the islower() method is used. This function only returns the value in terms of true or false.
str_check = "educba training" str_out = str_check.islower() print("Yes the given string is in lowercase",str_out) str_check1 = "EDUCBA TRAINING" str_out1 = str_check1.islower() print("No the given string is not in lowercase",str_out1)
From the above example, we can see the output if the given string is in small letters then it gives yes given string is in lowercase that is the value returned by the islower() method is “ true ” and if the given string is in capital letters then it gives no the given string is not in lowercase that is the value returned by the islower() method is “ false ”.
From the above two methods for lowercase: lower() and islower(), we have to note some points to remember while using these two methods. They are as follows:
- The lower() method does not take any parameters as it converts the string to lowercase, and if the parameters are given, then it will give a syntax error.
- The lower() method is applied or applies only to the characters or string. It only converts the capital letters into lowercase, and if the string is already in small or lowercase letters, then there will be no change in the output value; it returns the same as the original value.
- The lower() method is also not applicable to any digital characters or numbers and special symbols as there is nothing to convert into lowercase in special symbols and numbers.
- The islower() method also does not take any arguments or parameters; it checks the given string for lowercase characters and gives the output either true or false. If any parameters specified, then it will also give an error as a syntax error.
- The islower() method gives the output as true if the string is whitespace only.
- The islower() method also is applied to or applicable only to string or characters as it just checks the string if it is lowercase or no; if yes, then true, else false. So this method does not apply to digital characters or numbers and special symbols because there is nothing as lowercase or uppercase in numbers and special symbols.
Example #2 – lower() and islower() method
Now let us consider the example in which both lower() and islower() methods are used. The code is as below:
str = "EDUCBA Training" str_out = str.lower() print("The string converted in lowercase is:") print(str_out) print("\nTo check if the string is converted to lowercase") str_chk = str_out.islower() if str_chk is True: print("Yes the string is in lowercase.") else: print("No the string is not converterd into lowercase")
The above two methods are used in the programs where there is a need to check for the same strings; for example, when we are registering to some portal then, it will ask for username, email, passwords where the string matching is done as it asks to type twice for password and email where these methods can be used.
There are two methods in Python to check for lowercase and to convert uppercase alphabets to lowercase alphabets. The lower() method is used to convert the uppercase letters to lowercase letters, and it does not apply to numbers and special symbols. The islower() method is used to check whether the given string is in lowercase characters. Therefore the methods are used only for lowercase characters. These methods are only again used for alphabets but not on numbers and special symbols.
This is a guide to Lowercase in Python. Here we discuss the Introduction and examples of lowercase function in python. You may also have a look at the following articles to learn more –