Tutorial Study Image

Python casefold()

The casefold() function in python helps to convert the string to lowercase by removing all case distinctions present in the string. This is similar to the lower() method, but casefold() is more stronger and aggressive.


string.casefold() 
 

casefold() Parameters:

The casefold() method doesn't take any parameters. This method can find more matches when comparing two strings and can convert more characters to lowercase.

casefold() Return Value

The return value is always a string. This method ignores cases at the time of string comparison.

Input Return Value
string casefolded string

Examples of casefold() method in Python

Example 1: Python lowercase conversion using casefold()


string = "HOW ARE YOU"

# print lowercase string
print("After lowercase conversion:", string.casefold())
 

Output:


After lowercase conversion: how are you

Example 2: Strictly conversion using casefold()


string1 = "der Fluß"
string2 = "der Fluss"

# ß is equivalent to ss
if string1.casefold() == string2.casefold():
    print('The given strings are equal.')
else:
    print('The given strings are not equal.')
 

Output:


The given strings are equal.

Note: German lowercase letter ß is already lowercase,casefold() converts it to ss, if lower() method is used it does nothing.