
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Casefold String in Python
This function is helpful in converting the letters of a word into lowercase. When applied to two strings it can match their values irrespective of the type up of the case of the letters.
Applying casefold()
The below example we apply the casefold() function to a string and the result comes out in all lower case letters.
Example
string = "BestTutorials" # print lowercase string print(" lowercase string: ", string.casefold())
Output
Running the above code gives us the following result −
Lowercase String: besttutorials
Comparing using casefold()
We can compare two strings which have same letters but in different cases after applying the casefold() function. The result of the comparison gives a match of equality to the two words.
Example
string1 = "Hello Tutorials" string2 = "hello tutorials" string3 = string1.casefold() if string2==string3: print("String2 and String3 are equal") elif string1 != string3: print("Strings are not equal")
Output
Running the above code gives us the following result −
String2 and String3 are equal
Advertisements