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.
Related Posts:
- How do I do a case-insensitive string comparison?
- Can’t compare naive and aware datetime.now() <= challenge.datetime_end
- Check if two unordered lists are equal
- Comparing two dictionaries and checking how many (key, value) pairs are equal
- How does tuple comparison work in Python?
- Case insensitive regular expression without re.compile?
- How to convert list to string [duplicate]
- How to uninstall a package installed with pip install –user
- numpy max vs amax vs maximum
- TypeError: ‘str’ object is not callable (Python)
- ValueError: invalid literal for int() with base 10: ”
- Print string to text file
- Asking the user for input until they give a valid response
- Print a list in reverse order with range()?
- Configuring so that pip install can work from github
- Proper way to declare custom exceptions in modern Python?
- TypeError: ‘float’ object not iterable
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Importing class from another file [duplicate]
- Pandas group-by and sum
- Python List vs. Array – when to use?
- How to terminate a script?
- numpy array concatenate: “ValueError: all the input arrays must have same number of dimensions”
- csv.Error: iterator should return strings, not bytes
- ModuleNotFoundError: No module named ‘matplotlib’
- “inconsistent use of tabs and spaces in indentation”
- Pandas ‘count(distinct)’ equivalent
- How can I flush the output of the print function?
- Python calling method in class
- No module named pkg_resources
- Opening a .ipynb.txt File
- How do I remove all packages installed by PIP?
- Best way to replace multiple characters in a string?
- from PIL import Image – ImportError: No module named PIL
- Decoding UTF-8 strings in Python
- What does the Python error “name ‘self’ is not defined” mean?
- Python wildcard search in string
- How to have an array of arrays in Python
- LSTM Keras input shape confusion
- Detect whether a Python string is a number or a letter
- How to increase plt.title font size?
- ‘list’ object has no attribute ‘shape’
- How do I find the duplicates in a list and create another list with them?
- What is the meaning of single and double underscore before an object name?
- What is the difference between np.mean and tf.reduce_mean?
- How do I combine two dataframes?
- How can I get list of values from dict?
- How do I append one string to another in Python?
- Moving average or running mean
- How to select a drop-down menu value with Selenium using Python?
- ValueError: x and y must be the same size
- TypeError: ‘int’ object does not support item assignment
- Loading a file with more than one line of JSON into Pandas
- SystemError: new style getargs format but argument is not a tuple?
- How to convert bytearray to string in python
- Subtracting two lists in Python
- Is there any way to kill a Thread?
- Python Subprocess: Too Many Open Files
- urllib2.HTTPError: HTTP Error 403: Forbidden
- .write not working in Python
- Install Plotly in Anaconda
- ValueError: zero length field name in format in Python2.6.6
- Python NameError, variable ‘not defined’
- Cannot import cv2 in python in OSX
- numpy-equivalent of list.pop?
- How to get row number in dataframe in Pandas?
- Difference between Python’s Generators and Iterators
- “Unorderable types: int() < str()"
- python : an integer is required (got type str)
- Django Rest Framework — no module named rest_framework
- Accessing a class’ member variables in Python?
- Declaring a multi dimensional dictionary in python
- How do I compute derivative using Numpy?
- No module named utils error on compiling py file
- Convert Pandas Column to DateTime
- ImportError: cannot import name NUMPY_MKL
- Disable / Enable Button in TKinter
- Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support
- How do I find the time difference between two datetime objects in python?
- How to strip a specific word from a string?
- Tkinter error: Couldn’t recognize data in image file
- How to install Openpyxl with pip
- getting ZeroDivisionError: integer division or modulo by zero
- Iterating through list of list in Python
- Installing scipy for python 2.7
- Installing MySQL-python causes command ‘clang’ failed with exit status 1 on Mac OS 10.13.15
- Get difference between two lists
- how to build .exe for python 3.5+, 3.6 if possible?
- How to query as GROUP BY in django?
- Python regex match space only
- What is the most efficient way to store a list in the Django models?
- Convert list of dictionaries to a pandas DataFrame
- How to read html from a url in python 3
- Set variable in jinja
- Python how to write to a binary file?
- How to download a file via FTP with Python ftplib
- How do I restart a program based on user input?
- Python Pandas : pivot table with aggfunc = count unique distinct
- Flask Value error view function did not return a response [duplicate]