Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 两个unicode字符串的无大小写比较_Python - Fatal编程技术网

Python 两个unicode字符串的无大小写比较

Python 两个unicode字符串的无大小写比较,python,Python,我有两个用Unicode编码的字符串。我需要检查它们是否相同。对我来说,小写字母和大写字母没有区别。对于ascii字符串,最简单的方法是将两个字符串转换为大写,然后进行比较。但是,在Unicode中,这是不可能的。在不过滤非ascii字符的情况下进行无大小写比较的最佳方法是什么? 例如: str1:u'cat\xe0 1234' str2:u'CAT\xe0 1234'如果您尝试过,也可以使用unicode执行相同的操作 >>> u'cat \xe0 1234'.upper()

我有两个用Unicode编码的字符串。我需要检查它们是否相同。对我来说,小写字母和大写字母没有区别。对于ascii字符串,最简单的方法是将两个字符串转换为大写,然后进行比较。但是,在Unicode中,这是不可能的。在不过滤非ascii字符的情况下进行无大小写比较的最佳方法是什么? 例如: str1:u'cat\xe0 1234'
str2:u'CAT\xe0 1234'

如果您尝试过,也可以使用unicode执行相同的操作

>>> u'cat \xe0 1234'.upper() == u'CAT \xc0 1234'.upper()
True
>>> u'\u0431'.upper() == u'\u0411'.upper()
True