.casefold()
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
- hughlilly3 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- Anonymous contributorAnonymous contributor186 total contributions
- hughlilly
- christian.dinh
- Anonymous contributor
- 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.