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
#strings string_1 = "ABC" string_2 = "abc" #comparing two strings comparison = string_1.lower() == string_2.lower() #result print(comparison)
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.