📜  计算字符串python代码示例中的子字符串

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

代码示例4
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