In this article, we will learn how to convert the string to lowercase in python. There are various ways to convert the string to lowercase in python. We are converting a string to uppercase by using some methods such as python built-in function - lower()
function, by using ASCII value, By Using Loops, etc.
In this example, we will use the Python built-in function - lower()
to convert the string to lowercase
Example 1: Convert String to Lowercase using lower() Function
# Convert String to Lowercase using lower() Function
# Take the Input from the User
string = input("Enter the String: ")
string1 = string.lower()
print("\nOriginal String in Uppercase = ", string)
print("The Given String in Lowercase = ", string1)
Enter the String: TUTORIALS RACK IS AN online LEARNING WEBSITE
Original String in Uppercase = TUTORIALS RACK IS AN online LEARNING WEBSITE
The Given String in Lowercase = tutorials rack is an online learning website
In this example, we used the for
loop and python built-in function - chr()
and ord()
function to convert the string to lower case.
# Convert String to Lowercase using For Loop
# Take the Input from User
string = input("Enter the 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)
Enter the String: TUTORIALS RACK IS AN online LEARNING WEBSITE
Original String in Uppercase = TUTORIALS RACK IS AN online LEARNING WEBSITE
The Given String in Lowercase = tutorials rack is an online learning website
In this example, we used the while loop and python built-in function - chr()
and ord()
function to convert the string to lower case.
Example 3: Convert String to Lowercase using While Loop
# Convert String to Lowercase using While Loop
# Take the Input from User
string = input("Enter the 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)
Enter the String: TUTORIALS RACK IS AN online LEARNING WEBSITE
Original String in Uppercase = TUTORIALS RACK IS AN online LEARNING WEBSITE
The Given String in Lowercase = tutorials rack is an online learning website
In this example, we will convert the string using the ASCII value and python built-in function - chr()
and ord()
functions
Example 4: Convert String to Lowercase using ASCII Values
# Convert String to Lowercase using ASCII Values
# Take the Input from User
string = input("Enter The 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)
Enter the String: TUTORIALS RACK IS AN online LEARNING WEBSITE
Original String in Uppercase = TUTORIALS RACK IS AN online LEARNING WEBSITE
The Given String in Lowercase = tutorials rack is an online learning website
# Convert Uppercase String to Lowercase in Python
# Take the Input from User
string = input("Enter the 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)
Enter The String: TUTORIALS RACK IS AN online LEARNING WEBSITE
Original String in Uppercase = TUTORIALS RACK IS AN online LEARNING WEBSITE
The Given String in Lowercase = tutorials rack is an online learning website
I hope this article will help you to understand how to convert the string to lowercase in python
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments