How To Lowercase A String In Python?

Python provides different methods to convert strings into lowercase. Lowercase strings consist of only lowercase letters and there is not an uppercase letter. Lowercase is simply related to the letters, not numbers or special characters. For example “PythonTect” can be converted into the lowercase as “pythontect”.

Lowercase String with lower() Method

String variables and string values provide the lower() method as a built-in method to convert a string into lowercase. All letters in the string are converted into lowercase. Both string variables and string values provide the lower() method. In the following example, we convert string variables and string values into lowercase.

a = "ISMAIL"



Lowercase String with casefold() Method

Another method to convert string variable or string value into lowercase is casefold() method which is also provided by all string variables and string values.

a = "ISMAIL"



lower() vs casefold()

Both lower() and casefold() methods are used to convert strings into lowercase. Even they are very similar there are some minor differences between lower() and casefold() method. The lower() method is the Pythonic way to convert string to lowercase. Also, special letters like ;

# 'essen'


print("ESSEN" == "Eßen")

print("ESSEN".lower() == "Eßen".lower())

print("ESSEN".casefold() == "Eßen".casefold())

Leave a Comment