How to Ignore Case in Python?

Python Tutorials

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.

Leave a Reply

Your email address will not be published. Required fields are marked *