How to convert to lowercase in Python?

Lowercase is a typeface of capital letters. For eg 'a', 'b', 'c', etc are lowercase letters whereas 'A', 'B', 'C', etc are uppercase letters. This article discusses different approaches for the conversion of uppercase letters to lowercase in python.

Converting to lowercase letters using lower()

In Python, lower() is an inbuilt function that converts uppercase letters to lowercase letters. The lower() function returns a lowercase string and doesn't take any parameter. The syntax for the lower() method is given below.

#syntax:
string.lower()

Let us consider a string string_1 = "CHERCHER Tech". string_1.lower() returns the output as "chercher tech".

string_1 = "CHERCHER Tech"
print("string_1 : ", string_1)
print("Lowercase : ", string_1.lower())

Output

string_1 :  CHERCHER Tech
Lowercase :  chercher tech

Converting to lowercase letters using for loop

Consider a string string_1 = "CHERCHER Tech". A for loop iterates over the string. If the character of the string is in uppercase, the ord() function is used to get the ASCII value of the respective character. The difference between ASCII values of 'A' and 'a' is 32.

To convert the letter to lowercase 32 is added to the ASCII value of a particular character. The chr() function converts the integer value to a character and concatenates it to the variable lower_case.

If the character present in the string is in lower_case it is directly concatenated to variable lower_case.

string_1 = "CHERCHER Tech"
print("string_1", string_1)
lower_case = ""
for i in string_1:
    if i.isupper():
        ch = ord(i)
        val = ch + 32
        lower_case += chr(val)
    else:
        lower_case += i
print("Lowercase : ", lower_case)

The above code returns the output as

string_1 CHERCHER Tech
Lowercase :  chercher tech
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions