Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is casefold() in Python?

Mahnoor Zaheer

The casefold() method in Python converts all the uppercase letters in a string to lowercase letters. casefold() is similar to the lower() method, but is stronger and helps with changing letters to lowercase in other languages.

Syntax

The syntax of the casefold() method is as follows:


string.casefold()

Parameters

The casefold() function does not require any parameters.

Return value

The return value of casefold() is a string that contains all the lowercase letters. However, this method does not affect any symbols or numbers in the string.

Code

In the code below, the casefold() method converts all the uppercase letters of the string into lowercase. The German letter ‘ß’ does not get changed into ‘ss’ (lowercase form) through the lower() function, but casefold() converts it.

msg = "WELCOME"

# lowercase string
print("WELCOME using casefold() is", msg.casefold())

# German letter ß has lower case form ss
German_cap = "der Fluß"

# 'ß' is converted into to 'ss' through casefold() but not through lower()
print ("Lower output:", German_cap.lower())
print( "Casefold output:", German_cap.casefold())
Example code of the casefold() method in Python

RELATED TAGS

python
communitycreator
RELATED COURSES

View all Courses

Keep Exploring