def count_substring(string, sub_string): count=0 for pos in range(len(string)): if string[pos:].startswith(sub_string): count+=1 return count
Это может быть самым простым способом.