📜  计数字符串python代码示例

📅  最后修改于: 2022-03-11 14:45:13.569000             🧑  作者: 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