Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (1.6k points)
How can I do case insensitive string comparison in Python?

I would like to encapsulate comparison of a regular strings to a repository string using in a very simple and Pythonic way. I also would like to have ability to look up values in a dict hashed by strings using regular python strings.

1 Answer

0 votes
by (25.1k points)

You can just use the lower() function on string to convert both strings into lower case and compare them e.g.:

if str1.lower() == str2.lower()

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...