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 Custom Exceptions
Python issubclass()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Set discard()
Converting String to Stream of chars
Java – Generate Random String
Python Global Keyword
Python Dictionary clear()
Python sleep()
Python del Statement
Python Program to Create a Long Multiline String
Python all()
Python tuple()
Python Program to Find Hash of File
Python time Module
Python slice()
Python Directory and Files Management
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python List count()
Python String upper()
Python Program to Get the Class Name of an Instance
Python reversed()
Python dict()
Python String lower()
Python abs()
Python isinstance()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Create Pyramid Patterns
Python Function Arguments
Python Program to Find LCM
Python any()
Python Program to Make a Simple Calculator