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 sleep()
Python Data Types
Check if a String is a Palindrome in Java
Python String format()
Format ZonedDateTime to String
Python Exception Handling Using try, except and finally statement
Check If a String Is Numeric in Java
Python String ljust()
Python Function Arguments
Python Program to Find Sum of Natural Numbers Using Recursion
Python String join()
Python List copy()
Python String rstrip()
Python format()
Python Global Keyword
Python List pop()
Python round()
Python Program to Find Factorial of Number Using Recursion
Python getattr()
Python Program Read a File Line by Line Into a List
Python ord()
Python List reverse()
Python Program to Copy a File
Python Global, Local and Nonlocal variables
Python Program to Calculate the Area of a Triangle
Python List sort()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Errors and Built-in Exceptions
Adding a Newline Character to a String in Java
Python for Loop
Python Program to Find Numbers Divisible by Another Number
Python all()