【问题标题】:Check whether string exists in a string, no matter if uppercase/lowercase/mixed? [duplicate]检查字符串中是否存在字符串,无论是大写/小写/混合? [复制]
【发布时间】:2020-01-23 18:45:35
【问题描述】:

我想检查一个字符串是否存在于另一个字符串中,但是当我搜索该字符串时,我只能得到一个确认,当字符串完全一样时。我怎样才能绕过它?

【问题讨论】:

  • 在检查是否存在之前将两个字符串转换为相同的大小写。
  • string.lower()?

标签: python string


【解决方案1】:

试试这个,它在验证它们不同后检查字符串是否包含在string2中(不区分大小写):

string != string2 and str.lower(string) in str.lower(string2)

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 2021-08-12
    • 2018-08-22
    • 2016-03-01
    • 2015-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    相关资源
    最近更新 更多