Convert string to lowercase Python
In this post, you will learn how to convert a string to lowercase. Python provides in-built methods to convert strings to lowercase.
The lower() method of Python converts all letters or characters of a string from uppercase to lowercase.
Syntax of lower() function
string.lowercase()
The lower() method doesn't take any parameters. It returns the lowercase string from the given string.
Python convert a string to lowercase
str1 = "Welcome TO EtutorialsPOINT!"
print(str1.lower())
str2 = "BEST! Educational Resources 4432"
print(str2.lower())
Output of the above code:
welcome to etutorialspoint!
best! educational resources 4432
Python string to lowercase using lower() function
# Python program
# to compare strings
str1 = 'etutorialspoint - educational resources'
str2 = 'etutorialsPOINT - EducaTionAL ResouRCeS'
# Comparison of strings using
# lower() method
if(str1.lower() == str2.lower()):
print("Both strings are same.")
else:
print("Both strings are not same.")
Output of the above code:
Both strings are same.
Python string to lowercase using swapcase() function
The string swapcase() method of Python converts all uppercase characters to the lowercase and vice versa of the given string, and returns it. In the given Python program, this method converts all the uppercase to lowercase.
str1 = "ETUTORIALSPOINT"
print(str1.swapcase())
Output of the above code:
etutorialspoint
Python string to lowercase using casefold() function
The casefold() method in Python converts all the uppercase letters in a string to lowercase letters. The casefold() method is similar to the lower() method, but it is more aggressive.
str1 = "Welcome to ETUTORIALSPOINT!"
print(str1.casefold())
Output of the above code:
welcome to etutorialspoint!
Related Articles
Convert Python list to numpy arrayConvert string to list Python
Python program to list even and odd numbers of a list
Python loop through list
Sort list in descending order Python
Convert array to list Python
Python take screenshot of specific window
Web scraping Python BeautifulSoup
Check if two strings are anagrams Python
Python program to add two numbers
Print new line python
Python for loop index
Convert List to Dataframe Python
numpy random choice
Dictionary inside list python
Check if list is empty Python
Python raise keyword
Python program to get the largest number from a list
Python program to map two lists into a dictionary