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 Read a File Line by Line Into a List
Python bytes()
Deep Learning with Python - Francois Cholletf
Python List reverse()
Convert String to Byte Array and Reverse in Java
Python Program to Make a Flattened List from Nested List
Python Program to Swap Two Variables
Intelligent Projects Using Python - Santanu Pattanayak
Python List sort()
Java String to InputStream
Python String count()
Python property()
Python Program to Return Multiple Values From a Function
Converting String to Stream of chars
Python Global, Local and Nonlocal variables
Python Program to Count the Occurrence of an Item in a List
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python zip()
Python Set intersection()
Python Program to Add Two Numbers
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python __import__()
Most commonly used String methods in Java
Reading an HTTP Response Body as a String in Java
Python Program to Sort Words in Alphabetic Order
Python Program to Compute all the Permutation of the String
Python delattr()
Python Program to Print Colored Text to the Terminal
Python *args and **kwargs
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Program to Shuffle Deck of Cards