If you don't want to use str.lower(), you can use a regular expression:

import re

if re.search('mandy', 'Mandy Pande', re.IGNORECASE):
    # Is True
Answer from eumiro on Stack Overflow
🌐
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

Perform Case Insentive Search
This code works and returns 5 lines before the string ‘JUMP’, but need to make the search case-insensitive. Best, Dave from collections import deque def search(lines, pattern, history=1): previous_lines = deque(maxlen=history) for line in lines: if pattern in line: yield line, previous_lines ... More on discuss.python.org
🌐 discuss.python.org
5
0
July 30, 2021
help with IGNORECASE
https://docs.python.org/3/library/stdtypes.html#str.startswith startswith doesn't take an "ignore case" parameter because there are no circumstances under which it will ignore case. More on reddit.com
🌐 r/learnpython
2
1
October 31, 2022
Trying to create case-insensitive user search for list, but '.lower()' method isn't working, any help please?
It’s just as the interpreter says, list does not have a lower method. What would even be a lowecase list? You need to apply the method to all strings contained in the list. A list comprehension is perfect for this. More on reddit.com
🌐 r/learnpython
5
2
October 30, 2019
Check if case sensitive with python (with boolean)
Well, in general it's case sensitive by default. So you can do first check if the word is in a sentence, and it'll only match when it's case sensitive. Then you can convert both to lowercase letters only and check if the lower case version of the word is in the lower case version of the sentence. Since you want to do only one with a boolean check, try: case_sensitive = True if case_sensitive: #do casesensitive check else: #do lowercase check If you don't want it to be part of another word, i guess it's a bit harder. But you can convert the sentence to a list with .split() and then check if it's in that list, since that will be on a word by word basis. Edit: And also remove punctuation and such. More on reddit.com
🌐 r/learnpython
9
1
October 15, 2017
🌐
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.
🌐
Python.org
discuss.python.org › python help
Perform Case Insentive Search - Python Help - Discussions on Python.org
July 30, 2021 - This code works and returns 5 lines before the string ‘JUMP’, but need to make the search case-insensitive. Best, Dave from collections import deque def search(lines, pattern, history=1): previous_lines = deque(maxlen=history) for line in lines: if pattern in line: yield line, previous_lines previous_lines.append(line) # Example use on a file if __name__ == '__main__': with open('test.txt') as f: for line, prevlines in search(f, 'JUMP', 5): ...
🌐
Learning About Electronics
learningaboutelectronics.com › Articles › How-to-search-for-a-case-insensitive-string-in-text-Python.php
How to Search for a Case-Insensitive String in Text in Python
It will return all matches for 'python' regardless of the case of any characters of that string. ... We can use the re module in Python and use its findall() function.
🌐
AskPython
askpython.com › python-modules › python-regex-for-case-insensitive-text-matching
Python Regex for Case-Insensitive Text Matching without re.compile() - AskPython
May 12, 2023 - Python Modules · Case Insensitive Regular Expression Without Re Compile (1) Python’s ‘re’ module, short for regular expressions, provides a powerful toolset for pattern recognition in text. There is a module called “re” which stands for regular expression in Python which contains various in-built functions for performing special operations on text and string objects.
Find elsewhere
🌐
EyeHunts
tutorial.eyehunts.com › home › python string contains case insensitive | example code
Python string contains case insensitive | Example code
April 25, 2022 - Use the in operator with the lower() or upper() function and a generator expression to check if a string is in a list of strings to check the string contains case insensitive in Python.
🌐
thisPointer
thispointer.com › home › python › python : check if a string contains a sub string & find it’s index | case insensitive
Python : Check if a String contains a sub string & find it's index | case insensitive - thisPointer
April 30, 2023 - Python : Find occurrence count & all indices of a sub-string in another string | including overlapping sub-strings · To check if a given string or a character exists in an another string or not in case insensitive manner i.e.
🌐
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 - There are three main methods used to carry out case insensitive string comparison in python which are lower(), upper() and casefold().
🌐
GeeksforGeeks
geeksforgeeks.org › python-case-insensitive-string-counter
Python – Case Insensitive string counter | GeeksforGeeks
April 23, 2023 - This ensures case insensitivity while mapping and cumulating frequency. ... # Python3 code to demonstrate working of # Strings Frequency (Case Insensitive) # Using defaultdict() + lower() from collections import defaultdict # initializing list test_list = ["Gfg", "Best", "best", "gfg", "GFG", "is", "IS", "BEST"] # printing original list print("The original list is : " + str(test_list)) res = defaultdict(int) for ele in test_list: # lowercasing to cater for Case Insensitivity res[ele.lower()] += 1 # printing result print("Strings Frequency : " + str(dict(res)))
🌐
Reddit
reddit.com › r/learnpython › trying to create case-insensitive user search for list, but '.lower()' method isn't working, any help please?
r/learnpython on Reddit: Trying to create case-insensitive user search for list, but '.lower()' method isn't working, any help please?
October 30, 2019 -

Here is the relevant section of code as I originally wrote it:

  elif choice == "4":
      print('What would you like to find? ')
      search_item = input()
      if search_item not in thislist:
          print ("Not found in this list:")
      else:
          print ("Found in this list:")
      print(', '.join(thislist))

...but it turned out that this was case-sensitive to user input, which is not desired, so I tried...

  elif choice == "4":
      print('What would you like to find? ')
      search_item = input()
      if (search_item.lower() not in thislist.lower()):
          print ("Not found in this list:")
      else:
          print ("Found in this list:")
      print(', '.join(thislist))

...as mentioned, for instance here. But it doesn't work, and I get...

Traceback (most recent call last): File "main.py", line 39, in <module> if (search_item.lower() not in thislist.lower()): AttributeError: 'list' object has no attribute 'lower'

I'm guessing that maybe it's because one or both of these isn't a string, but I'm not sure how to fix that if that is really the problem. Any help please? TIA.

BTW, I'm using https://repl.it, as I don't have a Python IDE installed on my home PC.

🌐
TutorialsPoint
tutorialspoint.com › how-do-i-do-a-case-insensitive-string-comparison-in-python
How do I do a case-insensitive string comparison in Python?
June 10, 2025 - The upper() method in Python converts all characters in a string to uppercase. This method also returns a new string with all characters converted to uppercase. str1 = "Tutorialspoint" str2 = "TUTORIALSPOINT" if str1.upper() == str2.upper(): print("The strings are equal i.e., case-insensitive") else: print("The strings are not equal")
🌐
Delft Stack
delftstack.com › home › howto › python › python regex case insensitive
Case Insensitive Regex in Python | Delft Stack
December 6, 2023 - The re.IGNORECASE flag, which is used above, can also be written as re.I. This re.I flag is also used to search a case-insensitive pattern within a text. ... import re # Define the pattern to search for pattern_to_search = "python" # Define ...
🌐
Reddit
reddit.com › r/learnpython › check if case sensitive with python (with boolean)
r/learnpython on Reddit: Check if case sensitive with python (with boolean)
October 15, 2017 -

How do I count how many times a case sensitive word appears somewhere using a boolean.

So for example:

word = input("Search this word: ")

Then I want to check if case sensitive == True or False. If it's true, it will only find the exact same words.

Also, the word can't be a part of another word. So it may not find "Apple" in Applepie. But it can only find "Apple" if it's independent like this: Apple Pie

Top answer
1 of 2
2
Well, in general it's case sensitive by default. So you can do first check if the word is in a sentence, and it'll only match when it's case sensitive. Then you can convert both to lowercase letters only and check if the lower case version of the word is in the lower case version of the sentence. Since you want to do only one with a boolean check, try: case_sensitive = True if case_sensitive: #do casesensitive check else: #do lowercase check If you don't want it to be part of another word, i guess it's a bit harder. But you can convert the sentence to a list with .split() and then check if it's in that list, since that will be on a word by word basis. Edit: And also remove punctuation and such.
2 of 2
1
As an aside, you're using the terminology wrong, and in this case, I think it matters and will cause you further confusion along the line if you don't get it clear. I'm not being snarky. It could also be a language thing, as I don't know your native tongue or english dialect, and both of these things can mean we would say things differently. The phrase "Check if case sensitive" doesn't make sense. A word cannot be case sensitive. A program can be case sensitive, that is, it can be sensitive to differences in the upper/lower case letters in a string. A word can be, in Python parlance, lowercase, UPPERCASE, Titlecase or mIxEd case. We say identifiers are in CamelCaps if the first letter of each word in the name is capitalised. I think you are really asking how to control whether a string complarison is case-sensitive or not, and others have ably answered that question. I usually do this by lowercasing everything like this: if case_sensitive_mode and word.lower() in sometext.lower(): # do case insensitive stuff elif word in sometext: # do case sensitive stuff As you want to find distinct words, however, re (regex) is the correct approach. Hope that helps.
🌐
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.
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)
🌐
iO Flood
ioflood.com › blog › python-match-case
Python Case Matching: Your Ultimate Guide
January 24, 2024 - We’re converting the match object to a boolean using the bool() function, so it prints True when the pattern is found. For case-insensitive matching, we can use the re.IGNORECASE or re.I flag with the re.match() function.