Python-比较2个相同的字符串将返回'False'

时间:2019-04-19 14:20:02

标签: python string compare equals

当我比较这两个字符串时,得到的值为False

a = "comentar"
b = "️comentar"
print(a == b) # False

我该如何解决?我尝试更改两个字符串的编码,但是没有任何效果。

您可以在这里尝试:https://onlinegdb.com/HJ8xYLPq4

2 个答案:

答案 0 :(得分:6)

它们不相同。第一个字符是不同的(尽管看起来与裸眼相同)

尝试

 print([ord(c) for c in a])
 print([ord(c) for c in b])

答案 1 :(得分:2)

如果您可以忽略这样的细微差异,请尝试:

from difflib import SequenceMatcher

word_1 = "comentar"

word_2 = " comentar"

result = SequenceMatcher(a=word_1, b=word_2).ratio() > 0.9

print(result)

这将返回True

相关问题