相关疑难解决方法(0)

Python:字符串匹配中的lower()与casefold()并转换为小写

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

从我从谷歌的理解和上述两个功能的链接:lower()casefold()将转换为小写的字符串,但casefold()甚至会转换为不区分大小写的字母,如ß用德语ss.

关于希腊字母的所有内容,但我的问题一般:

  • 还有其他差异吗?
  • 哪一个更好地转换为小写?
  • 哪一个更好地检查匹配的字符串?

第2部分:

firstString = "der Fluß"
secondString = "der Fluss"

# ß is equivalent to ss
if firstString.casefold() == secondString.casefold():
    print('The strings are equal.')
else:
    print('The strings are not equal.')
Run Code Online (Sandbox Code Playgroud)

在上面的例子中,我应该使用:

lower() # the result is not equal which make sense to me

要么:

casefold() # which ß is ss and result is the
        # strings are equal. (since I am a beginner that still …
Run Code Online (Sandbox Code Playgroud)

python string python-2.7 python-3.x

17
推荐指数
2
解决办法
9876
查看次数

标签 统计

python ×1

python-2.7 ×1

python-3.x ×1

string ×1