English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python Basic Tutorial

Python Flow Control

Python Functions

Python Data Types

Python File Operation

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Python string casefold() usage and example

Python string methods

The casefold() method returns a string with all characters in lowercase.

The casefold() method will deletein stringAll existing case distinctions exist. It is used for case-insensitive matching, that is, case is ignored when comparing.

This method is similar to the Lower() method, but the casefold() method is more powerful and more aggressive, which means it converts more characters to lowercase and finds more matches when comparing two strings converted by the casefold() method.

For example, German lowercase lettersßequivalent toss. However, due toßis already in lowercase letters, the lower() method does not work on it. However, casefold() converts it toss.

The syntax of casefold() is:

string.casefold()

casefold() parameters

The casefold() method does not take any parameters.

casefold() return value

The casefold() method returns the string converted to lowercase.

Example1: Use casefold() to convert to lowercase letters

string = "PYTHON IS AWESOME"
# Print the lowercase string
print("Lowercase string:", string.casefold())

When running the program, the output is:

Lowercase string: python is awesome

Example2: Use casefold() for comparison

firstString = "der Flüss"
secondString = "der Fluss"
# ß is equivalent to ss
if firstString.casefold() == secondString.casefold():
    print('The strings are equal.')
else:
    print('The strings are not equal.')

When running the program, the output is:

The strings are equal.

Python string methods