Table of Contents
The casefold() method is an aggressive lower() method which converts strings to case folded strings for caseless matching.
The casefold() method removes all case distinctions present in a string. It is used for caseless matching, i.e. ignores cases when comparing.
For example, the German lowercase letter ß is equivalent to ss. However, since ß is already lowercase, the lower() method does nothing to it. But, casefold() converts it to ss.
The syntax of casefold() is:
string.casefold()
1. Parameters for casefold()
The casefold() method doesn’t take any parameters.
2. Return value from casefold()
The casefold() method returns the case folded string.
3. Example 1: Lowercase using casefold()
string = "PYTHON IS AWESOME"
# print lowercase string
print("Lowercase string:", string.casefold())
Output
Lowercase string: python is awesome
4. Example 2: Comparison using casefold()
firstString = "der Fluß"
secondString = "der Fluss"
# ß is equivalent to ss
if firstString.casefold() == secondString.casefold():
print('The strings are equal.')
else:
print('The strings are not equal.')
Output
The strings are equal.
Related posts:
How to Remove the Last Character of a String?
Python break and continue
Python Program to Convert Bytes to a String
Python Program to Convert Celsius To Fahrenheit
Python Program to Count the Number of Digits Present In a Number
Python while Loop
Python Tuple count()
Python compile()
Python format()
Case-Insensitive String Matching in Java
Python locals()
Python String replace()
Python id()
Python Dictionary update()
Python Program to Get the File Name From the File Path
Python String isspace()
Python pow()
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Catch Multiple Exceptions in One Line
Python reversed()
Python Set issuperset()
Python String lstrip()
Python hasattr()
Python String rpartition()
Python String count()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Program to Convert Decimal to Binary Using Recursion
Python Data Types
Python Multiple Inheritance
APIs in Node.js vs Python - A Comparison
Python Program to Create a Long Multiline String
Python Program to Append to a File