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
str.lower
Returns a copy of the string with all cased characters converted to lowercase. Uses Unicode simple lowercase mappings.
str.upper
Returns a copy of the string with all cased characters converted to uppercase. Non-cased characters (digits, punctuation, whitespace) are unchanged.
str.title
Returns a titlecased copy where the first letter of each word is uppercase and the rest are lowercase. Word boundaries are defined by any run of non-letter characters, including apostrophes.
str.replace
Returns a new string with all occurrences of substring old replaced by new. If count is given, only the first count occurrences are replaced.