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"
print(a.lower())
print("ISMAIL".lower())
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"
print(a.casefold())
print("ISMAIL".casefold())
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 ;
print("Eßen".casefold())
# 'essen'
print("Eßen".lower())
#'eßen'
print("ESSEN" == "Eßen")
#False
print("ESSEN".lower() == "Eßen".lower())
#False
print("ESSEN".casefold() == "Eßen".casefold())
#True