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:
Split a String in Java
Python Program to Find the Largest Among Three Numbers
Python Matrices and NumPy Arrays
Python Set isdisjoint()
Python Program to Count the Occurrence of an Item in a List
Python callable()
Python Set clear()
Python Program to Check if a Number is Positive, Negative or 0
Python String split()
Python List copy()
Python chr()
Python Program to Iterate Over Dictionaries Using for Loop
Python String rjust()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Program to Find Factorial of Number Using Recursion
Python Program to Generate a Random Number
Node.js vs Python for Backend Development
Python Set copy()
String Processing with Apache Commons Lang 3
Python Program to Display Fibonacci Sequence Using Recursion
Python Set difference_update()
Python bytes()
String Hashing
Python Dictionary clear()
Python String lower()
Python Program to Reverse a Number
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python @property decorator
Python Sets
Python String isupper()
Intelligent Projects Using Python - Santanu Pattanayak
Most commonly used String methods in Java