Python String casefold()

The casefold() method is an aggressive lower() method which converts strings to case folded strings for caseless matching.

The casefold() method removes all case distinctions present in a string. It is used for caseless matching, i.e. ignores cases when comparing.

For example, the German lowercase letter ß is equivalent to ss. However, since ß is already lowercase, the lower() method does nothing to it. But, casefold() converts it to ss.

The syntax of casefold() is:


Parameters for casefold()

The casefold() method doesn't take any parameters.

Return value from casefold()

The casefold() method returns the case folded string.

Example 1: Lowercase using casefold()


# print lowercase string
print("Lowercase string:", string.casefold())


Lowercase string: python is awesome

Example 2: Comparison using casefold()

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.
Did you find this article helpful?