Python String lower()

Python String lower() method converts all the uppercase characters in a string to lowercase characters and returns the string as output.

lower() Syntax

The Syntax of lower() method is:

string.lower()

lower() Parameters

The lower() method doesn’t take any parameters.

lower() Return Value

In Python string lower() method converts all the uppercase characters in a string to lowercase and returns the output of the string.

The lower() method will return the original string if the string doesn’t have any uppercase.

Example 1: Convert a string to lowercase

The following program converts all the uppercase characters in a string to lowercase.

# Program to convert uppercase characters to lowercase
text= "ItsMYCode Coding Simplified"
text2="HELLO WORLD"
print('Original String: ',text)
print('Original String: ',text2)

print('Lowercase String: ',text.lower())
print("Lowercase String: ", text2.lower())

Output

Original String:  ItsMYCode Coding Simplified
Original String:  HELLO WORLD
Lowercase String:  itsmycode coding simplified
Lowercase String:  hello world

Example 2: String with Alphanumeric characters

If the string contains numeric/digits, the lower() method will return as is. Only the characters with uppercase will be converted to lowercase and returned.

Note: The same logic applies to even symbols and special characters. Apart from uppercase, none of the other characters will be converted. It will be returned as-is.

# Program to convert Alphanumeric characters to lowercase
text= "Its 2:00PM IST in India"
text2="HELLO WORLD"
print('Original String: ',text)
print('Lowercase String: ',text.lower())

Output

Original String:  Its 2:00PM IST in India
Lowercase String:  its 2:00pm ist in india

Example 3: How to check if two strings are same in Python

Let’s take a look at real-time examples of when exactly we use the string lower() method. Generally, there are many use cases where we need to check if two strings are the same.


In the below use case, we check if the email address and the re-entered email address are the same or different.

# Program to check the email and re-enterd email is same or different
email= "info@itsmycode.com"
confirmemail="INFO@ITSMYCODE.COM"

if(email.lower() == confirmemail.lower()):
    print("Email Address are same")
else:
    print("Email Address are not same")

Output

Email Address are same
Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
List of Python free ebooks

List of Free Python Books

Table of Contents Hide Python SuccinctlyPython Data Science HandbookThink Python 2nd EditionAutomate the Boring Stuff with PythonMaking Games with Python & PygameData Structures and Algorithms in Python Google Python Style GuideA…
View Post