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

Tutoriel de base Python

Contrôle de flux Python

Fonctions en Python

Types de données en Python

Opérations de fichier Python

Python Objects and Classes

Python Date and Time

Advanced Python Knowledge

Python Reference Manual

Python string casefold() usage and example

Python string methods

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

The casefold() method will deletein stringall the differences in uppercase and lowercase exist. It is used for case-insensitive matching, that is, to ignore case when comparing.

This method is similar to the Lower() method, but the casefold() method is more powerful and 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ßis equivalent toss. However, sinceß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 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.')

When running the program, the output is:

The strings are equal.

Python string methods