To do case insensitive comparison in Python use string's casefold() function.
The casefold() method removes all case distinctions present in a string. It is used for Case Insensitive matching.
There is no parameters required for casefold() function and it returns the casefolded string.
string = "Python casefold EXAMPLE" # print lowercase print(string.casefold())
Result: python casefold exampleExample2:
>>> string1 = "This is Python's case sensitive Matching Example" >>> string2 = "This is python's case sensitive matching example" >>> string1 == string2 False >>> string1.casefold() == string2.casefold() True >>>
Admin on Dec 15, 2019 at 12:12 am
If you like dEexams.com and would like to contribute, you can write your article here or mail your article to email@example.com . See your article appearing on the dEexams.com main page and help others to learn.