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 ascii()
Python filter()
Python Program to Find Sum of Natural Numbers Using Recursion
How to Get Started With Python?
Python Dictionary popitem()
Python min()
Python String ljust()
Python Program to Swap Two Variables
Python Program to Transpose a Matrix
Python while Loop
Python Program to Check the File Size
Python Dictionary setdefault()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Global Keyword
Python Set union()
Python String translate()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Represent enum
Python String split()
Python max()
Python Exception Handling Using try, except and finally statement
Python dict()
Python hex()
Java – String to Reader
Python if...else Statement
Python Set difference_update()
Python String isidentifier()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python staticmethod()
Python time Module
Python String upper()
Generate a String