The casefold() method is removes all case distinctions present in a string. It is used for caseless matching, i.e. ignores cases when comparing.
For example, German lowercase letter ß is equivalent to ss. However, since ß is already lowercase, lower() method does nothing to it. But, casefold() converts it to ss.
The syntax of casefold() is:
The casefold() method doesn't take any parameters.
The casefold() method returns the casefolded string.
string = "PYTHON IS AWESOME"
# print lowercase string
print("Lowercase string:", string.casefold())
When you run the program, the output will be:
Lowercase string: python is awesome
firstString = "der Fluß"
secondString = "der Fluss"
# ß is equivalent to ss
if firstString.casefold() == secondString.casefold():
print('The strings are equal.')
print('The strings are not equal.')
The strings are equal.