Assuming ASCII strings:

string1 = 'Hello'
string2 = 'hello'

if string1.lower() == string2.lower():
    print("The strings are the same (case insensitive)")
else:
    print("The strings are NOT the same (case insensitive)")

As of Python 3.3, casefold() is a better alternative:

string1 = 'Hello'
string2 = 'hello'

if string1.casefold() == string2.casefold():
    print("The strings are the same (case insensitive)")
else:
    print("The strings are NOT the same (case insensitive)")

If you want a more comprehensive solution that handles more complex unicode comparisons, see other answers.

Answer from Harley Holcombe on Stack Overflow
Top answer
1 of 15
828

Assuming ASCII strings:

string1 = 'Hello'
string2 = 'hello'

if string1.lower() == string2.lower():
    print("The strings are the same (case insensitive)")
else:
    print("The strings are NOT the same (case insensitive)")

As of Python 3.3, casefold() is a better alternative:

string1 = 'Hello'
string2 = 'hello'

if string1.casefold() == string2.casefold():
    print("The strings are the same (case insensitive)")
else:
    print("The strings are NOT the same (case insensitive)")

If you want a more comprehensive solution that handles more complex unicode comparisons, see other answers.

2 of 15
741

Comparing strings in a case insensitive way seems trivial, but it's not. I will be using Python 3, since Python 2 is underdeveloped here.

The first thing to note is that case-removing conversions in Unicode aren't trivial. There is text for which text.lower() != text.upper().lower(), such as "ß":

>>> "ß".lower()
'ß'
>>> "ß".upper().lower()
'ss'

But let's say you wanted to caselessly compare "BUSSE" and "Buße". Heck, you probably also want to compare "BUSSE" and "BUẞE" equal - that's the newer capital form. The recommended way is to use casefold:

str.casefold()

Return a casefolded copy of the string. Casefolded strings may be used for caseless matching.

Casefolding is similar to lowercasing but more aggressive because it is intended to remove all case distinctions in a string. [...]

Do not just use lower. If casefold is not available, doing .upper().lower() helps (but only somewhat).

Then you should consider accents. If your font renderer is good, you probably think "ê" == "ê" - but it doesn't:

>>> "ê" == "ê"
False

This is because the accent on the latter is a combining character.

>>> import unicodedata
>>> [unicodedata.name(char) for char in "ê"]
['LATIN SMALL LETTER E WITH CIRCUMFLEX']
>>> [unicodedata.name(char) for char in "ê"]
['LATIN SMALL LETTER E', 'COMBINING CIRCUMFLEX ACCENT']

The simplest way to deal with this is unicodedata.normalize. You probably want to use NFKD normalization, but feel free to check the documentation. Then one does

>>> unicodedata.normalize("NFKD", "ê") == unicodedata.normalize("NFKD", "ê")
True

To finish up, here this is expressed in functions:

import unicodedata

def normalize_caseless(text):
    return unicodedata.normalize("NFKD", text.casefold())

def caseless_equal(left, right):
    return normalize_caseless(left) == normalize_caseless(right)
🌐
GeeksforGeeks
geeksforgeeks.org › python › case-insensitive-string-comparison-in-python
Case-insensitive string comparison in Python - GeeksforGeeks
July 15, 2025 - If the set has only one unique element, it prints "equal" otherwise, "unequal". casefold() method in Python performs a case-insensitive comparison that accounts for locale-specific character differences.
Discussions

How can I perform case-insensitive string comparison in Python? - Python - Data Science Dojo Discussions
I have two strings, and I want to compare them without considering their cases. How can I achieve this in Python? I have tried using the == operator, but it considers the case while comparing the strings. Here’s what I have done so far: This code snippet uses the lower() method to convert ... More on discuss.datasciencedojo.com
🌐 discuss.datasciencedojo.com
1
0
April 26, 2023
Case sensitive string comparison
As far as I know, it is case sensitive by default. May be you mean case insensitive? Can you give an example and the code you tried? More on reddit.com
🌐 r/learnpython
6
2
January 22, 2021
How do you compare two strings without case-sensitivity? ("rat" = "Rat")
a.nocasecmp_to(b) returns 0 if a and b are equal, ignoring case. More on reddit.com
🌐 r/godot
13
3
October 5, 2024
Need help with case insensitive list comparison in Python
You could just make both names lower-case when doing the comparison/search More on reddit.com
🌐 r/learnprogramming
5
1
August 26, 2019
🌐
TutorialsPoint
tutorialspoint.com › article › how-do-i-do-a-case-insensitive-string-comparison-in-python
How do I do a case-insensitive string comparison in Python?
March 24, 2026 - Before using strcoll(), we need to set the appropriate locale using locale.setlocale(), then the comparison will be done in a case-insensitive way by converting strings to lowercase or uppercase before passing to the strcoll() method. import ...
🌐
Mathspp
mathspp.com › blog › how-to-work-with-case-insensitive-strings
How to work with case-insensitive strings | mathspp
January 21, 2023 - The method str.casefold is the method that you want to use when you need to do caseless, or case-insensitive, comparisons in Python.
🌐
LabEx
labex.io › tutorials › python-how-to-compare-two-python-strings-for-equality-in-a-case-insensitive-manner-395043
How to compare two Python strings for equality in a case-insensitive manner? | LabEx
Let's modify our script to add some examples that demonstrate when case-insensitive comparison is helpful: ## Add these examples to string_comparison.py ## Example: User searching for content user_search = "Python" article_title = "Getting Started with python Programming" ## Case-sensitive comparison (might miss relevant content) found_sensitive = user_search in article_title print(f"Case-sensitive search found match: {found_sensitive}") ## What if we want to find matches regardless of case?
🌐
Delft Stack
delftstack.com › home › howto › python › case insensitive string comparison in python
How to Compare String Case Insensitive String in Python | Delft Stack
February 2, 2024 - The next step is to compare both ... has introduced how to carry out the case insensitive string comparison using the lower() method....
Find elsewhere
🌐
LearnPython.com
learnpython.com › blog › python-case-sensitive
Is Python Case-Sensitive? | LearnPython.com
Using the casefold() method is the strongest and the most aggressive approach to string comparison in Python. It’s similar to lower(), but it removes all case distinctions in strings.
🌐
Data Science Dojo
discuss.datasciencedojo.com › python
How can I perform case-insensitive string comparison in Python? - Python - Data Science Dojo Discussions
April 26, 2023 - I have tried using the == operator, but it considers the case while comparing the strings. Here’s what I have done so far: This code snippet uses the lower() method to convert both strings to lowercase before comparing them using the == operator.
🌐
Python Guides
pythonguides.com › case-insensitive-string-comparisons-in-python
How To Do Case-Insensitive String Comparisons In Python?
March 19, 2025 - In most cases, using either lower() or casefold() will yield the same results for case-insensitive comparisons. However, if you need to handle special characters or follow the Unicode case folding algorithm, casefold() is the recommended choice. Read How to Check if a String is a Boolean Value ...
🌐
DEV Community
dev.to › bowmanjd › case-insensitive-string-comparison-in-python-using-casefold-not-lower-5fpi
Case-insensitive string comparison in Python using casefold, not lower - DEV Community
February 9, 2026 - Here is a discipline I am trying to adopt in my Python programs: use "My string".casefold() instead of "My string".lower() when comparing strings irrespective of case. When checking for string equality, in which I don't care about uppercase ...
🌐
TutorialsPoint
tutorialspoint.com › article › python-program-to-compare-two-strings-by-ignoring-case
Python Program to compare two strings by ignoring case
April 17, 2023 - The most common approach is converting both strings to lowercase using the lower() method before comparison ? string1 = "Hello" string2 = "hello" if string1.lower() == string2.lower(): print("The strings are equal, ignoring case.") else: print("The ...
🌐
Bowmanjd
bowmanjd.com › python-casefold
Case-insensitive string comparison in Python using casefold, not lower | Jonathan Bowman
July 15, 2020 - Here is a discipline I am trying to adopt in my Python programs: use "My string".casefold() instead of "My string".lower() when comparing strings irrespective of case. When checking for string equality, in which I don’t care about uppercase vs. lowercase, it is tempting to do something like ...
🌐
iO Flood
ioflood.com › blog › using-python-to-compare-strings-methods-and-tips
Python String Comparison Methods | Quick User Guide
August 13, 2024 - Because the strings are identical, they are stored in the same memory location and you just have to check that two strings point to the same memory. Case insensitive comparisons require additional processing.
🌐
Vultr Docs
docs.vultr.com › python › standard library › str › casefold()
Python str casefold() - Case Insensitive Comparison
December 30, 2024 - The str.casefold() method in Python is essential for performing case-insensitive text comparisons or lookups. This method is particularly useful when comparing text strings where case variation is irrelevant, such as usernames or hashtags, making ...
🌐
YouTube
youtube.com › watch
Python Tips and Tricks: Case-Insensitive String Comparisons Done Right - YouTube
How to perform case-insensitive string comparisons, and how to avoid somecommon Unicode issues.#mathbyteacademy #python #pythontipsCode for this Video=======...
Published: July 11, 2022
🌐
Squash
squash.io › string-comparison-in-python-best-practices-and-techniques
String Comparison in Python: Best Practices and Techniques
May 21, 2024 - Note that string comparison in ... case-insensitive string comparison, you can convert the strings to lowercase or uppercase using the lower() or upper() string methods ......
🌐
Codefinity
codefinity.com › courses › v2 › cf552d00-2991-4d8d-bab2-82d8904406ce › 6457ac36-df42-4b04-9e0f-a66a3a4c7027 › 0863d4fb-233e-46a5-990c-911c9a1c6b4e
Learn Comparing Strings | Cross-Type Interactions
12345 # Comparing two email addresses entered with different letter cases email_saved = "Support@Codefinity.com" email_entered = "support@codefinity.COM" print(email_saved.lower() == email_entered.lower()) # True → emails match regardless of case ... casefold() is a stronger, international-friendly variant of lower() and is a better default for case-insensitive comparisons.
🌐
GeeksforGeeks
geeksforgeeks.org › python-case-insensitive-string-replacement
Case insensitive string replacement in Python - GeeksforGeeks
April 5, 2025 - Explanation: re.sub(r"(?i)best", lambda m: "good", a) uses a case-insensitive regex ((?i) inline flag) to match the word "best" in any casing within the string a, and replaces each match using a lambda function that returns "good". This method splits the string into individual words using split(). ...