username = 'MICHAEL89'
if username.upper() in (name.upper() for name in USERNAMES):
    ...

Alternatively:

if username.upper() in map(str.upper, USERNAMES):
    ...

Or, yes, you can make a custom method.

Answer from nmichaels on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › case-insensitive-string-comparison-in-python
Case-insensitive string comparison in Python - GeeksforGeeks
July 15, 2025 - Explanation: This code uses casefold() for accurate case-insensitive comparison, especially with international characters. It converts all strings, checks uniqueness using a set and prints "equal" if all are identical otherwise, "unequal". re.match() checks if a string matches a pattern from the start and with the re.IGNORECASE flag, it ignores case differences.
🌐
EyeHunts
tutorial.eyehunts.com › home › python string contains case insensitive | example code
Python string contains case insensitive | Example code
April 25, 2022 - str1 = "Messi is the best SoCceR player" if "soccer" in str1.lower(): print("Contain soccer") if "Player" in str1: print("Contain football") ... Answer: Make the string lowercase or uppercase before matching it. ... Do comment if you have any doubts or suggestions on this Python string topic.
🌐
Mathspp
mathspp.com › blog › how-to-work-with-case-insensitive-strings
How to work with case-insensitive strings | mathspp
January 21, 2023 - To implement a case-insensitive dictionary in Python, we need to use the string method str.casefold whenever we are setting, getting, or deleting a key from the dictionary.
🌐
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 - As our main string doesn’t contains the sub-string ‘Hello’ therefore ‘not in’ operator returned True. Check if First Letter of String is Uppercase in Python ... 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.
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. This is a more efficient way to make case-insensitive comparisons in Python.
🌐
Codecademy
codecademy.com › article › how-to-check-if-a-string-contains-a-substring-in-python
How to Check if a String Contains a Substring in Python | Codecademy
The built-in .lower() method in Python converts all the characters of a string to lowercase. This method is especially helpful for case-insensitive string comparisons and searches because it maintains consistency and avoids mismatches resulting from different capitalizations by ensuring all characters are lowercase.
🌐
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 - 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") ... The casefold() method in Python is similar to the lower() method, but the difference is caseless matching, which is useful for comparing strings containing special characters or Unicode.
🌐
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 - It returns a string with all the characters converted into lower case alphabets. We can convert two strings to the lower case with the lower() method and then compare them case-insensitively.
🌐
Metaschool
metaschool.so › home › software development › master string searches in python 2025
Master String Searches in Python 2025
February 7, 2025 - Yes, string containment checks in Python are case-sensitive by default. This means that the check will distinguish between uppercase and lowercase characters. For instance, checking if "hello" is in "Hello World" will return False because of ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-case-insensitive-string-replacement
Case insensitive string replacement in Python - GeeksforGeeks
July 23, 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".
🌐
DataScientYst
datascientyst.com › pandas-contains-using-case-insensitive-search
Pandas: Contains Using Case Insensitive Search
May 16, 2025 - To perform case-insensitive string matching in Pandas, you can use the .str accessor along with regular expressions and the case=False parameter (1) parameter case of str.contains df1['col'].str.contains("MaX", na=False, case=False) (2) Margin ...
🌐
Python
python.org › dev › peps › pep-0235
PEP 235 -- Import on Case-Insensitive Platforms | Python.org
February 21, 2001 - Despite that the filesystem is case-insensitive, Python insists on a case-sensitive match.
🌐
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
- Whole word matches: 3 - All matches: 3 Scenario: No matches Text: 'No matches here' - Whole word matches: 0 - All matches: 0 Scenario: Mixed word boundaries Text: 'Python-script and PythonProgram contain python' - Whole word matches: 1 - All matches: 3 · This demonstrates how case-insensitive comparison can be used in a real-world search function, with options to handle different searching requirements.