The casefold Method in Python: Converting a String to Casefolded Form

Returns a copy of the string in casefolded form. Similar to converting to lowercase, but more aggressive.

For example, the letter “ß” in lowercase in German corresponds to the combination “ss”. However, since “ß” is already in lowercase, the lower() method will not change it, whereas casefold() converts it to “ss”.

casefold()

'ß'.lower()  # 'ß'
'ß'.casefold()  # 'ss'

'groß'.casefold() == 'gross'  # True