📌  相关文章
📜  从字符串 python 代码示例中返回给定子字符串的计数

📅  最后修改于: 2022-03-11 14:47:11.891000             🧑  作者: Mango

代码示例3
def count_substring(string,sub_string):
    l=len(sub_string)
    count=0
    for i in range(len(string)-len(sub_string)+1):
        if(string[i:i+len(sub_string)] == sub_string ):      
            count+=1
    return count