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 divmod()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Check Whether a String is Palindrome or Not
Array to String Conversions
Python Program to Split a List Into Evenly Sized Chunks
Python Operator Overloading
Python List extend()
Python pass statement
Python super()
Python Keywords and Identifiers
Python Program to Merge Mails
Python any()
Python format()
String Initialization in Java
Python Functions
Python Program to Merge Two Dictionaries
Converting a Stack Trace to a String in Java
Python Shallow Copy and Deep Copy
Python bytes()
Python Dictionary items()
Python String translate()
Python Program to Check If a String Is a Number (Float)
Python Set symmetric_difference()
Python isinstance()
Python String splitlines()
Python ascii()
Python dir()
Python Program to Convert Kilometers to Miles
Check if a String is a Palindrome in Java
Python Program to Check if a Number is Positive, Negative or 0
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Program to Find Factorial of Number Using Recursion