Python-如何进行不区分大小写的字符串比较?

如何在Python中进行不区分大小写的字符串比较?

我想以一种非常简单且Pythonic的方式封装对常规字符串与存储库字符串的比较。我还希望能够使用常规python字符串在由字符串散列的字典中查找值。

回答:

假设ASCII字符串:

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-如何进行不区分大小写的字符串比较? 的全部内容, 来源链接: utcz.com/qa/435828.html

回到顶部