Python String lower() Method

Python String lower() method is “used to convert all uppercase characters in a string into lowercase characters and returns it.”

Syntax

string.lower()

Parameters

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

Return Value

The lower() method returns the lowercase string from the given string. It converts all uppercase characters to lowercase. If no uppercase characters exist, it returns an original string.

Example 1: How to convert uppercase string to lowercase in Python

To convert uppercase string to lowercase string, use the string.lower() method.

string = "EXPECTO PATRONUM"
print("Original String:", string)

lower_case = string.lower()
print("Lowercase String:", lower_case)

Output

Original String: EXPECTO PATRONUM

Lowercase String: expecto patronum

It is a straightforward example that needs no explanation.

Example 2: String with Alphanumeric Characters

str = "MLM20 MLM30"
 
print("Original String:")
print(str)
 
print("\nConverted String:")
print(str.lower())

Output

Original String:
MLM20 MLM30

Converted String:
mlm20 mlm30

How to check if a string is in lowercase

To check if a string is in lowercase in Python, you can use the “string.islower()” method. The islower() method returns a True or False boolean value.

string = "Avada Kedavra"

print(string.islower())

Output

False

It returns False because the input string’s first character is uppercase.

Comparison of strings using the lower() method

str1 = "MLM20 MLM30"
str2 = "mlm30 mlm20"

if (str1.lower() == str2.lower()):
  print("Strings are same")
else:
  print("Strings are not same")

Output

Strings are not same

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.