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 enumerate()
Python Program to Delete an Element From a Dictionary
Python List copy()
Python Program to Count the Occurrence of an Item in a List
Python complex()
Why String is Immutable in Java?
Python range()
Python Tuple count()
Python vars()
Python String rstrip()
Python String rsplit()
Python Type Conversion and Type Casting
Python Program to Find Sum of Natural Numbers Using Recursion
Java InputStream to String
String Initialization in Java
Deep Learning with Python - Francois Chollet
Python Program to Safely Create a Nested Directory
String Set Queries
Check if a String is a Palindrome in Java
Python Closures
Convert String to Byte Array and Reverse in Java
APIs in Node.js vs Python - A Comparison
JavaScript Eval: run a code string
Python Program to Create a Countdown Timer
Python Program to Make a Simple Calculator
Python float()
Python String format_map()
Python Program to Print Hello world!
Python Program to Generate a Random Number
Python Multiple Inheritance
Python Program to Convert Two Lists Into a Dictionary
Python List pop()