Python Lowercase - All you need to know

In this short tutorial, we are going to look into what Python lowercase methods are. We will also consider some examples to clearly understand the concepts.

Table of Contents - Python Lowercase

  • An Introduction to Python lowercase
  • Syntax and parameters
  • Python lower() with examples
  • Python islower() with examples
  • Closing thoughts
  • Other Related Concepts

An Introduction to Python lowercase

While working with strings, there might be instances where we need to convert uppercase strings to lowercase format. Or we might have to check if a given string is lowercase or not. Python facilitates this with the following functions:
The Python lower() method is used to convert uppercase letters in a string to lowercase. The islower() method, on the other hand, returns True if all the letters in a string are lowercase.

An example of a real-life use case for this function would be you wanting to convert all the entered email addresses of your users to lowercase letters. Strings are case sensitive So this is a common practice to ensure that another account is not created with a similar but uppercase email ID.

Syntax and parameters

The syntax of the method lower() is:
string.lower()
As you can see, the method does not take any parameters. In the place of the string we enter the name of the variable containing the string.


Python lower() with examples

In this section, we learn about the Python lower() method. This method is used to convert uppercase string to lowercase in Python. It returns a modified string and not a newly created string.
In an instance where there are no uppercase letters, it returns the original string.

Input:

# python program for lower() function
email_id = input("Please enter your email ID: ")
print("Original ID: ",email_id)
modified_email = email_id.lower()
print("The lowered ID: ",modified_email)

Output:

email_id = input("Please enter your email ID: ")
print("Original ID: ",email_id)
modified_email = email_id.lower()
print("The lowered ID: ",modified_email)
In the above code snippet, the user is asked to enter an email address. The original ID is first printed for the purpose of easy comparison post modification. Then the code email_id.lower() is used to direct the lower() function to the variable [email_id()] it needs to consider for conversion. Finally, the modified string is printed post conversion to lowercase.

Python islower() with examples

Before we convert a string to lowercase, we might have to check if it is already in lowercase. The islower() method checks every case-based character. If it finds any characters in uppercase it returns False, else it returns True.

Input:

email_001 = "flexiple@gmail.com" 
print (email_001.islower()) 
email_002 = "FLEXIPLE@gmail.com" 
print (email_002.islower())

Output:

True
False
In the output of our first print statement, the method has returned True. This is because the function found lowercase characters in the string. Whereas, the second print statement has printed out False. This is because the string contains only uppercase letters as well.

Closing thoughts

Swapping the character cases is a common string operation in Python. In this Python tutorial, we looked at how the lower() method is used. We learned how the islower() method is used to check a given string. We also looked into a couple of examples to understand both the methods completely. Check out how the upper() function works as well for further clarity.