Python 3 reference · String Methods

Python String casefold() Method

Return a case-folded copy for caseless comparison. Stronger than lower(): it also handles special cases like German ß.

Python 3 Since 3.3

Syntax

str.casefold()

Return value

A new string.

Examples

casefold() vs lower()Try it yourself
print("Straße".casefold(), "Straße".lower())

Output

strasse straße
Case-insensitive comparisonTry it yourself
a, b = "STRASSE", "straße"
print(a.lower() == b.lower(), a.casefold() == b.casefold())

Output

False True

When to use it

Use casefold() whenever you compare text without caring about case, especially user input in any language. Use lower() when you need lower-case text for display.

Version history

VersionChange
Python 3.3Added