本文介绍了如何在Python中进行不区分大小写的字符串比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Python中进行不区分大小写字符串比较的最好方法是什么?
What's the best way to do case insensitive string comparison in Python?
我想将一个常规字符串与一个存储库字符串进行比较,和pythonic方式。我也想有能力在字符串使用普通的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. Much obliged for advice.
推荐答案假设ASCII字符串:
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)"更多推荐
如何在Python中进行不区分大小写的字符串比较?
发布评论