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
print("Straße".casefold(), "Straße".lower())
Output
strasse straße
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
| Version | Change |
|---|---|
| Python 3.3 | Added |
Related
str.lower()· Return a copy of the string with all cased characters converted to lower case.str.upper()· Return a copy of the string with all cased characters converted to upper case.- Python Strings · tutorial