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 Numbers, Type Conversion and Mathematics
Most commonly used String methods in Java
Python Set copy()
Python bytes()
Format ZonedDateTime to String
Python compile()
Python Function Arguments
Python Program to Represent enum
Python super()
Python time Module
Python RegEx
Check if a String is a Palindrome in Java
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python hash()
Python String maketrans()
Python String replace()
Python Dictionary fromkeys()
Python Program to Count the Occurrence of an Item in a List
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Why String is Immutable in Java?
Python String istitle()
Python Sets
Python Strings
Python Set discard()
Converting a Stack Trace to a String in Java
Python if...else Statement
Python Program to Check if a Key is Already Present in a Dictionary
Python chr()
Python String rstrip()
Python Matrices and NumPy Arrays
Python Deep Learning Cookbook - Indra den Bakker
Python getattr()