Summary: In this tutorial, you will learn to compare two strings case-insensitively (i.e., ignore case) in Python.

When comparing two strings, Python interprets uppercase and lowercase letters differently.

For example, “ABC” is not the same as “abc“. When ignoring the case, these strings are the same.

In Python, you can easily ignore case by using str.lower() during comparison.

Use str.lower() to Ignore Case

string_1 = "ABC"
string_2 = "abc"

#comparing two strings
comparison = string_1.lower() == string_2.lower()


Output: True

In this program, we called str.lower() method to lowercase all the characters of strings. After this, we used them when comparing to ignore case.

Adarsh Kumar

I am an engineer by education and writer by passion. I started this blog to share my little programming wisdom with other programmers out there. Hope it helps you.

Leave a Reply