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 Set issubset()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Create Pyramid Patterns
Python getattr()
Python max()
Python Program to Count the Number of Each Vowel
Why String is Immutable in Java?
Python sorted()
Python Program to Copy a File
Python Program to Concatenate Two Lists
Convert char to String in Java
Python Program to Print Output Without a Newline
Python Decorators
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Deep Learning with Python - Francois Cholletf
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Program to Convert Bytes to a String
Reading an HTTP Response Body as a String in Java
Python Program to Create a Long Multiline String
Python List copy()
Python String format_map()
Python Program to Print the Fibonacci sequence
Python Program to Multiply Two Matrices
Python Program to Get the Last Element of the List
Python Program to Check If Two Strings are Anagram
Python Program to Convert Kilometers to Miles
Python Program to Get the File Name From the File Path
Python Objects and Classes
Python String islower()
Python Program to Catch Multiple Exceptions in One Line
Python Operator Overloading
Python Program to Represent enum