.casefold()
Anonymous contributor
Anonymous contributor194 total contributions
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”:
All contributors
- Anonymous contributorAnonymous contributor194 total contributions
- hughlilly3 total contributions
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributor
- hughlilly
- christian.dinh
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.