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)
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
Python allows you to compare strings, but it is not case sensitive. Mark true or false.
Find step-by-step Computer science solutions and the answer to the textbook question Python allows you to compare strings, but it is not case sensitive. Mark true or false.. More on quizlet.com
🌐 quizlet.com
1
Python allows you to compare strings, but it is not case sensitive.
Python allows you to compare strings, but it is not case sensitive. More on askfilo.com
🌐 askfilo.com
1
January 4, 2025
Python allows you to compare strings, but it not case sensitive in that comparison.Question 11 options: True False
Python allows you to compare strings, but it not case sensitive in that comparison. ... Here’s the best way to solve it. ... I'll work through this problem step by step. In Python, string comparison is done using comparison ...View the full answer More on chegg.com
🌐 chegg.com
1
February 16, 2024
🌐
LearnPython.com
learnpython.com › blog › python-case-sensitive
Is Python Case-Sensitive? | LearnPython.com
This is the most popular approach to case-insensitive string comparisons in Python. The lower() method converts all the characters in a string to the lowercase, making it easier to compare two strings.
🌐
iO Flood
ioflood.com › blog › using-python-to-compare-strings-methods-and-tips
Python String Comparison Methods | Quick User Guide
August 13, 2024 - In addition to these techniques, ... the == operator is used to compare string objects. Case sensitivity is a crucial aspect to consider when comparing strings 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 start by exploring how string comparisons work in Python and why case sensitivity matters. In Python, when you compare two strings using the equality operator (==), the comparison is case-sensitive by default.
🌐
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 - In Python, string comparisons are case-sensitive by default. For example, when we consider the strings "Hello" and "hello" then they are considered as two different strings because of the difference in their letter casing.
🌐
Squash
squash.io › string-comparison-in-python-best-practices-and-techniques
String Comparison in Python: Best Practices and Techniques
May 21, 2024 - Python's string comparisons are case-sensitive by default, meaning that uppercase and lowercase letters are treated as distinct characters.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › case-insensitive-string-comparison-in-python
Case-insensitive string comparison in Python - GeeksforGeeks
April 22, 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.
🌐
Kanaries
docs.kanaries.net › topics › Python › is-python-case-sensitive
Is Python Case Sensitive? – Kanaries
August 18, 2023 - Python is a case-sensitive programming language, meaning it distinguishes between uppercase and lowercase characters. This feature allows for greater flexibility in creating variable names, functions, modules, classes, and constants. However, it also requires developers to be mindful of their ...
🌐
Brainly
brainly.com › english › high school › python allows you to compare strings, but it is not case sensitive. true or false
[FREE] Python allows you to compare strings, but it is not case sensitive. True or False - brainly.com
June 14, 2023 - Python is case sensitive when comparing strings, meaning that two strings with the same characters in different cases are not considered equal.
🌐
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 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 both strings to lowercase before comparing them using the == operator.
🌐
DataWider
datawider.com › articles › python case insensitive string comparison: every method you need to know
Python Case Insensitive String Comparison: Every Method You Need to Know
May 7, 2026 - String comparison in Python is case-sensitive by default. "Hello" and "hello" are not equal as far as Python is concerned. But in most real applications, you don’t want that distinction to matter.
🌐
Medium
medium.com › @sami.hamdiapps › elevate-your-python-skills-string-comparison-python-made-easy-bd0b3b08b55b
Elevate Your Python Skills: String Comparison Python Made Easy | by Sami Hamdi | Medium
September 4, 2023 - At the core of Python string comparison Python are four operators: ==,!=, = and >=. These allow you to compare strings based on their lexicographic order — effectively alphabetic order. ... Note that Python is case-sensitive when comparing strings.
🌐
Cherry Servers
cherryservers.com › home › blog › cloud computing › how to do string comparison in python [with examples]
How to do String Comparison in Python | Cherry Servers
November 7, 2025 - Those are: ... These operators ... as the result of the comparison. Character comparison is done based on their Unicode values, which makes the comparison operation case-sensitive......
🌐
TutorialsPoint
tutorialspoint.com › article › is-python-case-sensitive-or-case-insensitive
Is Python case-sensitive or case-insensitive?
March 26, 2026 - Python is case-sensitive, treating uppercase and lowercase letters as different characters. Use proper naming conventions and leverage .lower() or .upper() methods when you need case-insensitive string comparisons.
🌐
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
String comparisons in Python are case-sensitive by default. If user input may vary in capitalization or include extra spaces, normalize first, then compare.
🌐
Quora
quora.com › Is-Python-is-a-case-sensitive-language
Is Python is a case sensitive language? - Quora
Answer (1 of 2): Yes , python is a case sensitive language . Case-insensitive means the string which you have written should exactly be the same as a string which is to be compared but both strings can be either in upper case or lower case. Eg — world and WORLD means two different variable ...