Python Program to Convert String to Lowercase

Write a Python program to Convert String to Lowercase using the lower function, For Loop, while loop, and ASCII with an example.

Python Program to Convert String to Lowercase using lower Function

This python program allows the user to enter a string. Next, we used a built-in string function called lower to convert upper case characters in a string to lowercase.

TIP: Please refer String article to understand everything about Python Strings.

# Python Program to Convert String to Lowercase
 
string = input("Please Enter your Own String : ")

string1 = string.lower()
 
print("\nOriginal String in Uppercase  =  ", string)
print("The Given String in Lowercase =  ", string1)

Convert Python String to Lowercase output

Please Enter your Own String : HELLO WORLD

Original String in Uppercase  =   HELLO WORLD
The Given String in Lowercase =   hello world

Python Program to Convert String to Lowercase using For Loop

This python program allows the user to enter a string. Next, it finds the uppercase letters and converts them to lowercase.

First, we used For Loop to iterate characters in a String. Inside the For Loop, we used the If Else Statement to check the character is between A and Z or not. If true, we are adding 32 to its ASCII value. Otherwise, we are coping that character to string 1.

TIP: Please refer ASCII Value of Total Characters article and ASCII table to understand the ASCII values.

# Python Program to Convert String to Lowercase
 
string = input("Please Enter your Own String : ")
string1 = ''

for i in range(len(string)):
    if(string[i] >= 'A' and string[i] <= 'Z'):
        string1 = string1 + chr((ord(string[i]) + 32))
    else:
        string1 = string1 + string[i]
 
print("\nOriginal String in Uppercase  =  ", string)
print("The Given String in Lowercase =  ", string1)
Please Enter your Own String : WELCOME TO TUtoriaL GATEWAY

Original String in Uppercase  =   WELCOME TO TUtoriaL GATEWAY
The Given String in Lowercase =   welcome to tutorial gateway

Program to Convert String to Lowercase using While Loop

This python string uppercase to lowercase conversion program is the same as above. However, we just replaced the For Loop with While Loop.

string = input("Please Enter your Own String : ")
string1 = ''
i = 0

while(i < len(string)):
    if(string[i] >= 'A' and string[i] <= 'Z'):
        string1 = string1 + chr((ord(string[i]) + 32))
    else:
        string1 = string1 + string[i]
    i = i + 1
 
print("\nOriginal String in Uppercase  =  ", string)
print("The Given String in Lowercase =  ", string1)
Please Enter your Own String : PYTHON TUTORIAL

Original String in Uppercase  =   PYTHON TUTORIAL
The Given String in Lowercase =   python tutorial

Convert Uppercase String to Lowercase Example 4

This Python code to change uppercase to lowercase is the same as the second example. However, we are using For Loop with Object

# Python Program to Convert String to Lowercase
 
string = input("Please Enter your Own String : ")
string1 = ''

for i in string:
    if(i >= 'A' and i <= 'Z'):
        string1 = string1 + chr((ord(i) + 32))
    else:
        string1 = string1 + i
 
print("\nOriginal String in Uppercase  =  ", string)
print("The Given String in Lowercase =  ", string1)
Python Program to Convert String to Lowercase 4

Python to Convert String to Lowercase using ASCII Values

In this program, we are comparing the ASCII values to check there are any uppercase characters. If true, we are converting them to lowercase.

# Python Program to Convert String to Lowercase
 
string = input("Please Enter your Own String : ")
string1 = ''

for i in string:
    if(ord(i) >= 65 and ord(i) <= 90):
        string1 = string1 + chr((ord(i) + 32))
    else:
        string1 = string1 + i
 
print("\nOriginal String in Uppercase  =  ", string)
print("The Given String in Lowercase =  ", string1)
Please Enter your Own String : TUTORIAL GATEWAY

Original String in Uppercase  =   TUTORIAL GATEWAY
The Given String in Lowercase =   tutorial gateway