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:
Java String to InputStream
Python String expandtabs()
Jackson – Marshall String to JsonNode
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Parse a String to a Float or Int
Python Program to Copy a File
Python Program to Print Colored Text to the Terminal
Python Dictionary
Deep Learning with Python - Francois Cholletf
Python String replace()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Java InputStream to String
Python Program to Return Multiple Values From a Function
Python String upper()
Python Tuple index()
Python open()
Python dict()
Python Custom Exceptions
Python float()
Encode a String to UTF-8 in Java
Generate a String
Python String strip()
Python super()
Count Occurrences of a Char in a String
Python Program to Capitalize the First Character of a String
Converting a Stack Trace to a String in Java
Python Program to Check Prime Number
Python String rsplit()
Python round()
Python String find()
Python pow()