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 Find LCM
Python Program to Check If a String Is a Number (Float)
Python Program to Find Factorial of Number Using Recursion
Python List append()
Node.js vs Python for Backend Development
Python Program to Access Index of a List Using for Loop
Python Multiple Inheritance
Python callable()
CharSequence vs. String in Java
Python Program to Print Hello world!
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python for Loop
Python Tuple
Python Program to Find Sum of Natural Numbers Using Recursion
Python if...else Statement
Python len()
Python Set union()
Python Program to Print the Fibonacci sequence
Python Modules
Python strftime()
Python Set clear()
Python Package
Jackson – Marshall String to JsonNode
Python Program to Iterate Through Two Lists in Parallel
Python Program to Extract Extension From the File Name
Python eval()
Python Program to Count the Number of Each Vowel
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Set intersection_update()
Python Dictionary copy()
Python Program to Convert Celsius To Fahrenheit
Python String format_map()