- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
casefold() string in Python Program
In this tutorial, we are going to discuss the string method str.casefold(). It doesn't take any arguments. The return value of the method is a string that is suitable for the caseless comparisons.
What are caseless comparisons? For example, the german lower case letter ß is equivalent to ss. The str.casefold() method returns the ß as ss. It converts all the letters to lower case.
# initialising the string string = "TUTORIALSPOINT" # printing the casefold() version of the string print(string.casefold())
If run the above program, you will get the following result.
Let's see the example where caseless comparison works. If you directly compare the string ßtutorialspoint with sstutorialspoint, we will get False as output. Let's see the code.
# initialising the string string = "ßtutorialspoint" second_string = "sstutorialspoint" # comparing two strings print(string == second_string)
As we expected the result of the above program is False.
Now, compare the same using the str.casefold() method.
# initialising the string string = "ßtutorialspoint" second_string = "sstutorialspoint" # comparing two strings print(string.casefold() == second_string)
If you run the above code, you will get the following results.
If you have any doubts regarding the tutorial, mention them in the comment section
- Related Articles
- casefold() string in Python
- Program to perform string compression in Python
- Concatenated string with uncommon characters in Python program
- Convert a list to string in Python program
- How to reverse a string in Python program?
- Python program to Mark duplicate elements in string
- Program to swap string characters pairwise in Python
- Python program to sort string in custom order
- Program to check string contains consecutively descending string or not in Python
- Program to check the string is repeating string or not in Python
- Program to find a good string from a given string in Python
- Python Program to find mirror characters in a string
- Python program to Count words in a given string?
- Removing nth character from a string in Python program
- Program to evaluate s-expression as string in Python