← Go Back

How to Do Case-Insensitive String Comparison

String comparisons in Python are case-sensitive, since what is being compared are the characters in the string, and the characters that represent uppercase letters are different from those that represent lowercase letters. For example:

>>> a = "Hello"
>>> b = "HELLO"
>>> a == b
False

To perform a case-insensitive comparison, you can convert both to lowercase for comparison:

>>> a = "Hello"
>>> b = "HELLO"
>>> a.lower() == b.lower()
True

Note that, because strings in Python are immutable, the lower() method does not work in-place (i.e., original values are not altered.)

strings


🐍 You might also find interesting: