lower() function is used to convert a string into all lowercase letters. The Python
isLower() method will check if a string is all lowercase and return
isLower() functions are useful for fields like email where all letters should be lowercase.
When you’re working with a string in Python, you may want to convert the contents of that string to lowercase. For example, you may be creating a signup form that converts a user’s email to lowercase. This is a common practice used to ensure that another account cannot be created using the same email in uppercase because strings are case sensitive.
The Python built-in function
lower() can be used to convert a string into lowercase and return a copy of the revised string. In addition, the Python
isLower() method can be used to check whether or not all the characters within a string appear in lowercase.
In this tutorial, we will discuss how to use the
isLower() methods to work with lowercase strings. We will explore examples for each of these methods to show how they can work in a Python program.
Strings are used to store text-based data in programming languages. In Python, strings are enclosed within either single (
‘ ’) or double quotation marks (
“ ”). Regardless of your choice, you should stick to the same style throughout the program when you are working with strings. Here’s an example of a string in Python:
good_morning = "What a wonderful morning!"
Strings are case sensitive, which means that two strings with the same text but different cases will not be considered equal. This is important to understand, because if you are working with a string that should be unique, you may want to convert it to a certain case so that you can compare it with other similar strings in your program.
lower() string method can be used to convert all case-based characters in a string into lowercase. So, this method will take all the uppercase letters in your string and return a copy of the string with only lowercase letters.
Here’s the syntax for the Python
lower() function takes in no parameters and is appended after a string, like the above.
To show off how
lower() works, we’ll use an example. Let’s say that we are creating a signup form and we want to convert the email address a user inserts into lowercase. We could do so by using the following code:
email = input("What is your email address?") print(email) final_email = email.lower() print(final_email)
Upon execution, our code returns the following strings:
What is your email address? aLex@gmail.com aLex@gmail.com email@example.com
There’s a lot going on, so let’s simplify things. On the first line, we declare a variable called
On the next line, we declare a variable called
final_email which converts the contents of the
final_email, which returns our original string but in lowercase.
lower() will return symbols and numbers in their regular state because those characters are not case sensitive.
Before you convert a string to lowercase, you may want to evaluate whether that string is already in lowercase. That’s where the
isLower() method comes in.
isLower() method checks whether all letters in a string are in lowercase. The method returns a True or False value based on whether the string contains only lowercase characters. Here’s the syntax for the Python
isLower() does not take any parameters. Instead, it is appended to the end of a string value.
Let’s use an example to showcase how the
lower() method works. For instance, before we convert a user’s email to lowercase, we want to check if it is already in lowercase. We could do so as the following:
email = input("What is your email address?") print(email.isLower())
If we run our program and insert the email “aLex@gmail.com”, our code returns the following:
What is your email address? aLex@gmail.com False
The string “aLex@gmail.com” contains one uppercase character—the
L—and so the
isLower() method decided that it was False. Meanwhile, if we were to insert the email “firstname.lastname@example.org” into our program, we would receive the following output:
What is your email address? email@example.com True
isLower() will return True even if the string contains whitespace, digits, and/or symbols. Only lowercase letters that are found in the string will cause
isLower() to evaluate it as False.
lower() method can be used to convert a string into lowercase and return a revised copy of the string. The Python
isLower() function can be used to check whether or not a string contains an uppercase character.
In this tutorial, we’ve explored the two main Python lowercase methods:
isLower(). We also examined a few examples of these methods in action. So now you have the knowledge you need to work with lowercase strings like a Python expert!