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 String isnumeric()
Python String startswith()
Python List
Python Dictionary clear()
Python Program to Make a Flattened List from Nested List
Python Deep Learning Cookbook - Indra den Bakker
Convert String to Byte Array and Reverse in Java
Node.js vs Python for Backend Development
Python vars()
Python strftime()
Python Program to Find Sum of Natural Numbers Using Recursion
Python String rpartition()
Python round()
Python dir()
Python Dictionary
Python format()
Python List clear()
Python Keywords and Identifiers
Check If a String Is Numeric in Java
Python Machine Learning Eqution Reference - Sebastian Raschka
Converting String to Stream of chars
Python hasattr()
Python Dictionary copy()
Python help()
Python Program to Create Pyramid Patterns
Python Program to Check Whether a String is Palindrome or Not
Python Program to Get the Full Path of the Current Working Directory
Python Dictionary values()
Converting a List to String in Java
Deep Learning in Python - LazyProgrammer
Python Dictionary setdefault()
Python staticmethod()