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.
The syntax of the casefold()
method is as follows:
string.casefold()
The casefold()
function does not require any parameters.
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.
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 stringprint("WELCOME using casefold() is", msg.casefold())# German letter ß has lower case form ssGerman_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())