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 Program to Count the Number of Digits Present In a Number
Python Program to Get File Creation and Modification Date
Python Directory and Files Management
Python Dictionary clear()
Python staticmethod()
Python Program to Check Whether a String is Palindrome or Not
Python round()
Python strftime()
Python Program to Print all Prime Numbers in an Interval
Python Set difference_update()
How to Remove the Last Character of a String?
Python Program to Compute the Power of a Number
Python String upper()
Python sorted()
Python ascii()
Deep Learning in Python - LazyProgrammer
Python Program to Check Armstrong Number
Python String center()
Python Set isdisjoint()
Python getattr()
Python List insert()
Python String ljust()
Python Program to Check If Two Strings are Anagram
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Converting a Stack Trace to a String in Java
Python Program to Sort a Dictionary by Value
Python String isnumeric()
APIs in Node.js vs Python - A Comparison
String Processing with Apache Commons Lang 3
Python Operator Overloading
Introduction to Scientific Programming with Python - Joakim Sundnes
Python String rpartition()