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:
Count Occurrences of a Char in a String
Python Program to Capitalize the First Character of a String
Python List pop()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python min()
Python Program to Parse a String to a Float or Int
Python Program to Count the Number of Digits Present In a Number
Python Program to Check Leap Year
Python id()
Deep Learning in Python - LazyProgrammer
Python sorted()
Python RegEx
Python String rsplit()
Python Set copy()
Python Program to Represent enum
Map to String Conversion in Java
Python Keywords and Identifiers
How to get current date and time in Python?
Python Tuple index()
Python String istitle()
Intelligent Projects Using Python - Santanu Pattanayak
Python complex()
Python locals()
Python Function Arguments
Check if a String is a Palindrome in Java
Python Program to Convert String to Datetime
Python bin()
Python Sets
Python Program to Get Line Count of a File
Python Program to Find HCF or GCD
Python Custom Exceptions
Python String isnumeric()