.casefold()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published May 10, 2021Updated Dec 21, 2021
Contribute to Docs

The .casefold() method returns a copy of a string with all characters in lowercase. It is similar to .lower(), but whereas that method deals purely with ASCII text, .casefold() can also convert Unicode characters.

Syntax

"String".casefold() # Output: string

Example 1

Below is an example of casefold() being used to set all characters in a string to lowercase:

my_string_1 = "THIS SHOULD ALL BE IN LOWERCASE!"
print(my_string_1.casefold())

The output would be:

this should all be in lowercase!

Example 2

my_string_2 = "this Should ALSO Be Entirely In Lowercase!"
print(my_string_2.casefold())

The output would be:

this should also be entirely in lowercase!

Codebyte Example

.casefold() can convert a wider scope of characters than .lower() can, including characters unique to human languages. Take the German lowercase letter “ß”, for example. While .lower() cannot convert it, .casefold() can convert it to “ss”:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy