【问题标题】:how do you check if a string has more than one specific character in python. Example The string, 'mood' would clearly have two 'o' characters [duplicate]如何检查一个字符串在 python 中是否有多个特定字符。示例字符串“mood”显然有两个“o”字符[重复]
【发布时间】:2019-09-15 08:19:01
【问题描述】:

如何检查一个字符串在 python 中是否有多个特定字符。示例字符串 'mood' 显然有两个 'o' 字符

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    您可以使用str.count 方法:

    >>> 'mood'.count('o') > 1
    True
    >>>
    

    【讨论】:

      猜你喜欢
      • 2020-07-16
      • 2014-06-23
      • 2014-11-24
      • 2016-06-27
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      相关资源
      最近更新 更多