编程语言
首页 > 编程语言> > python – 如何进行不区分大小写的字符串比较?

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,case-insensitive,comparison
来源: https://codeday.me/bug/20190911/1803115.html