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 islower()
Python Program to Find the Sum of Natural Numbers
Split a String in Java
Python Numbers, Type Conversion and Mathematics
Python Program to Get the File Name From the File Path
Python String strip()
Python Set clear()
Python Dictionary pop()
Python String partition()
Python memoryview()
Python Strings
Python Program to Split a List Into Evenly Sized Chunks
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Set difference()
Converting a Stack Trace to a String in Java
Python Dictionary clear()
Python help()
Python Dictionary keys()
Python List copy()
Python Program to Find All File with .txt Extension Present Inside a Directory
APIs in Node.js vs Python - A Comparison
Python hasattr()
Python Program to Remove Punctuations From a String
Java – Generate Random String
Python oct()
Python List
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python int()
Python String splitlines()
Python Program to Generate a Random Number
Java InputStream to String
Python String replace()