casefold() string in Python
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 reverseiflist(str)==list(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.
Recommended Posts:
- Python PIL | BoxBlur() method
- Python | sympy.ones() method
- Python | sympy.zeros() method
- Python | sympy.eye() method
- How to write an empty function in Python - pass statement?
- Operator Functions in Python | Set 2
- Count words in a given string
- Rearrange a string so that all same characters become d distance away
- Time Functions in Python | Set-2 (Date Manipulations)
- Send mail from your Gmail account using Python
- Python – The new generation Language
- Print Single and Multiple variable in Python
- Increment and Decrement Operators in Python
- str() vs repr() in Python
- Swap two variables in one line in C/C++, Python, PHP and Java



