How do I do a case-insensitive string comparison?
You can convert both strings to lowercase or uppercase (using the lower() or upper() method) before doing the comparison.
You can convert both strings to lowercase or uppercase (using the lower() or upper() method) before doing the comparison.
Python code snippet for case-insensitive string comparison:
Convert strings to lowercase with lower() method in Python
python— editable, runs on the server
Info
Watch a video course: Python - The Practical Guide
or
Convert strings to uppercase with upper() method in Python
python— editable, runs on the server
In this example, the comparison will be true and the message "The strings are case-insensitively equal." will be printed.