.casefold()
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”:
Contribute to Docs
- 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.
Learn Python on Codecademy
- Skill path
Analyze Data with Python
Learn to analyze and visualize data using Python and statistics.Includes 8 CoursesWith CertificateIntermediate13 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours