Menu Close
Python string casefold()

Python string casefold() method is a string method that is used to convert string to case folded string. Python string casefold() method is just like the lower() method that removes distinctions present in the string.

In the previous tutorial, we have seen all about the Python string capitalize() method to convert the first character of any string into an upper case letter.

Python String casefold() Method

string casefold() method is a python string built-in method that is used to convert string to casefold string or lower case. string casefold function is an aggressive lower method that converts strings to lower case for caseless matching.

Syntax:

The syntax of Python string casefold() is:-

string.casefold() 

Parameter of casefold():

The casefold() method does not take any parameter.

Return value from casefold():

The return value from casefold() method is casefolded string.

Let’s see an example for using the python casefold() string method.

Python string casefold() Example:

In this string casefold function example, we will understand the string casefold() method using different examples.

Example 1:

In this example, we will convert string str to lower case using casefold() method.


str = "PROGRAMMING"
print("Old string:- ", str)

str2 = str.casefold()
print("New string:- ",str2)

Output


Old string:- PROGRAMMING
New string:- programming

Example 2:

Here we have string str with a collection of upper case and lower case. Now we will convert str to case folded string using string casefold function.


str = "PyThOn"
print("Old string:- ", str)

str2 = str.casefold()
print("New string:- ",str2)

Output

Old string:-  PyThOn
New string:-  python

Example 3:

If the first character of the string will be Number, Then the string casefold() method still convert the string to lower case except for the number.


str = "12Python programming"
print("Old string:- ", str)

str2 = str.casefold()
print("New string:- ",str2)

Output

Old string:-  12Python programming
New string:-  12python programming

Conclusion:

In this article, You have learned what is the Python string casefold() method and how to use the string casefold() method.
I hope this tutorial will help you. If you like this article, please comment and share it with your friends who want to learn Python programming from scratch to advanced.

More Python tutorials:- Click Here

For More Information:- Click Here

Python string capitalize() method
Python String center() Method

Related Posts