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:
Python Dictionary get()
Python String rstrip()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python isinstance()
Python Errors and Built-in Exceptions
Python String startswith()
Python classmethod()
Python bytearray()
Python Dictionary items()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Set symmetric_difference()
Python filter()
Python issubclass()
Python len()
Python String format()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Converting String to Stream of chars
Case-Insensitive String Matching in Java
Python Program to Get the Class Name of an Instance
Python Program to Return Multiple Values From a Function
Python Program to Display Powers of 2 Using Anonymous Function
Python Sets
Check If a String Is Numeric in Java
Python sum()
Python repr()
Python Program to Represent enum
Java – String to Reader
Converting a List to String in Java
Python Program to Get the File Name From the File Path
Converting String to Stream of chars
Python input()
Python Set copy()