From the course: Effective Serialization with Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Case-insensitive comparison

Case-insensitive comparison - Python Tutorial

From the course: Effective Serialization with Python

Start my 1-month free trial

Case-insensitive comparison

- [Instructor] Sometimes you would like to compare strings in a case insensitive method. Let's start by Python. And then we're going to say, that p1 and p2 is Python starting with a capital P, and Python, a lower case. So, if you'll try to compare them, they will not be equal. However, we can use the lower method, to compare them, in a case insensitive method. In some other languages, this can fail. The Sigma Greek letter, can have three forms, depending on its position in the sentence. Here are the three forms of the Sigma letter. An s1.lower, equals s2.lower, this is going to be true. But if you're going to compare it, to the other form of Sigma, this is not going to work. What we can do, is to use the casefold method, which is exactly for that. And it works on the first and the second, and also on the first and the third. So, if you're doing a case insensitive comparison, here's the casefold method.

Contents