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 frozenset()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python float()
Python map()
Python Set issuperset()
Python min()
Python Dictionary popitem()
Python Tuple count()
Python List append()
Python Set difference()
Python Functions
Python String rstrip()
Python Program to Display Fibonacci Sequence Using Recursion
Python Dictionary pop()
Python Global, Local and Nonlocal variables
Python Program to Swap Two Variables
Python Program to Concatenate Two Lists
Reading an HTTP Response Body as a String in Java
Python Program to Capitalize the First Character of a String
Python Program to Find the Factors of a Number
Python String isalnum()
Python time Module
Python Object Oriented Programming
Python Program to Print all Prime Numbers in an Interval
Node.js vs Python for Backend Development
Python iter()
Python Program to Create Pyramid Patterns
Convert String to int or Integer in Java
Python Numbers, Type Conversion and Mathematics
Python List remove()
Python Set symmetric_difference_update()
Python String rjust()