The casefold() string method is used to implement caseless string matching. It is similar to lower() string method but case removes all the case distinctions present in a string. i.e ignore cases when comparing.
Syntax:
string.casefold() Parameters : the casefold doesn't take any parameters. return value: it return the casefolded string the string converted to lower case.
Examples
- Convert string in lower case
# Python program to convert string in lower casestring=" GEEKSFORGEEKS"# print lowercase stringprint(" lowercase string: ",string.casefold())chevron_rightfilter_noneOutput:
lowercase string: geeksforgeeks
- Check if a string is palindrome
# Program to check if a string# is palindrome or not# change this value for a different outputstr='geeksforgeeks'# make it suitable for caseless comparisonstr=str.casefold()# reverse the stringrev_str=reversed(str)# check if the string is equal to its reverseifstr==rev_str:print("palindrome")else:print(" not palindrome")chevron_rightfilter_noneOutput:
not palindrome
- Count vowels in a string
# Program to count the number of each# vowel in a string# string of vowelsv='aeiou'# change this value for a different resultstr='Hello, have you try geeksforgeeks?'# input from the user# str = input("Enter a string: ")# caseless comparisionsstr=str.casefold()# make a dictionary with each vowel a key and value 0c={}.fromkeys(v,0)# count the vowelsforcharinstr:ifcharinc:c[char]+=1print(c)chevron_rightfilter_noneOutput:
{'o': 3, 'e': 6, 'a': 1, 'i': 0, 'u': 1}
This article is contributed by Shivani Baghel. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Python | Check if a given string is binary string or not
- Python | Check if given string can be formed by concatenating string elements of list
- Python | Check if string ends with any string in given list
- Python | Sorting string using order defined by another string
- Python | Merge Tuple String List values to String
- Python | Sort each String in String list
- Python | Convert List of String List to String List
- Python - Length of shortest string in string list
- Python - Remove front K characters from each string in String List
- Python - Remove String from String List
- Python | Delimited String List to String Matrix
- String Alignment in Python f-string
- String to Int and Int to String in Python
- Pad or fill a string by a variable in Python using f-string
- Python - Filter String Tuples if String lengths equals K
- Python - Create a string made of the first and last two characters from a given string
- String slicing in Python to check if a string can become empty by recursive deletion
- String slicing in Python to rotate a string
- Python String Methods | Set 2 (len, count, center, ljust, rjust, isalpha, isalnum, isspace & join)
- Python String Methods | Set 3 (strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs())
Improved By : Anamitra Musib

