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 Set union()
Python Set issubset()
Python String rjust()
Python Set isdisjoint()
Python max()
Python Exception Handling Using try, except and finally statement
Python type()
Python String strip()
Python Program to Find HCF or GCD
How to Remove the Last Character of a String?
Python help()
Python Program to Split a List Into Evenly Sized Chunks
Python Program to Convert Kilometers to Miles
Python Program to Check Leap Year
Python super()
Python List remove()
Python Program to Add Two Numbers
Python String title()
Python String replace()
Python Generators
Python Program to Check if a Number is Odd or Even
Python Program to Find the Sum of Natural Numbers
Python Program to Remove Punctuations From a String
Python hash()
Python Program to Check Armstrong Number
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Append to a File
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python datetime
Python Program to Randomly Select an Element From the List
Split a String in Java
Python Program to Calculate the Area of a Triangle