Skip to main content

casefold()

The casefold() method in Python is a string method that returns a lowercase version of the string. It is similar to the lower() method but more aggressive in converting characters to lowercase, making it suitable for caseless comparisons.

Parameter Values

This function does not accept any parameters.

Return Values

The casefold() method returns a string with all characters converted to lowercase.

How to Use casefold() in Python

Example 1:

The casefold() method returns a casefolded copy of the string. Casefolded strings may be used for caseless matching.

text = 'HELLO WORLD'
result = text.casefold()
print(result)  # Output: 'hello world'
Example 2:

It is similar to lower() but can casefold some characters that are linguistically appropriate. For example, the German ß becomes 'ss'.

german_word = 'STRAßE'
result = german_word.casefold()
print(result)  # Output: 'strasse'