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 Print Output Without a Newline
Python List insert()
Format ZonedDateTime to String
Python Program to Add Two Numbers
Python Program to Access Index of a List Using for Loop
Python List index()
Map to String Conversion in Java
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python help()
Reading an HTTP Response Body as a String in Java
Python String lstrip()
Python time Module
Python List Comprehension
Python Program to Extract Extension From the File Name
Python String rsplit()
Java – Reader to String
Python Input, Output and Import
Python Program to Represent enum
Python Namespace and Scope
Machine Learning with Python for everyone - Mark E.Fenner
Python Operators
Python Multiple Inheritance
Python String expandtabs()
Python String isnumeric()
Python repr()
Python Dictionary copy()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python round()
Python Strings
Python sleep()
Python sum()
Deep Learning with Applications Using Python - Navin Kumar Manaswi