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 Add Two Numbers
Python any()
Java String to InputStream
Python round()
Python String strip()
Python Program to Delete an Element From a Dictionary
Why String is Immutable in Java?
Intelligent Projects Using Python - Santanu Pattanayak
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python while Loop
Python Program to Transpose a Matrix
Python Program to Calculate the Area of a Triangle
Python divmod()
Python chr()
Python Decorators
Python Program to Differentiate Between type() and isinstance()
Python Program to Split a List Into Evenly Sized Chunks
Check if a String is a Palindrome in Java
Python Dictionary update()
Python property()
String Initialization in Java
Python String isdigit()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python min()
Python Program to Find the Factorial of a Number
Python String lower()
Python Iterators
Python Program to Access Index of a List Using for Loop
Check If a String Is Numeric in Java
Deep Learning in Python - LazyProgrammer
Python List count()
Python Program to Check Whether a String is Palindrome or Not