transformation

str.casefold

Returns a casefolded copy suitable for caseless matching. Stronger than lower(): it applies full Unicode case folding, e.g. German 'ß' becomes 'ss'.

str.casefold()

Parameters

Parameter Purpose
self operates on the calling string; takes no arguments
returns new casefolded str — for comparison, not display

Examples

>>> 'STRAßE'.casefold()
'strasse'

ß folds to 'ss' (lower() leaves it as ß)

>>> 'straße'.casefold() == 'STRASSE'.casefold()
True

the correct way to compare strings case-insensitively

>>> 'Hello'.casefold()
'hello'

for plain ASCII behaves like lower()

>>> 'İ'.casefold()
'i̇'

handles Turkish dotted I via full Unicode folding

Gotcha

casefold() output is meant for comparison, not display. It is generally not reversible and may change string length.

Related methods

← All Python string methods · Python built-ins