(string, sub_string)
| 6 | """ |
| 7 | |
| 8 | def count_substring(string, sub_string): |
| 9 | end=len(sub_string) |
| 10 | c=0 |
| 11 | for i in range(len(string)): |
| 12 | #if starting character of substring is found in i-th position of string |
| 13 | if(string[i]==sub_string[0]): |
| 14 | """if all the characters from i-th position to i+length of substring |
| 15 | are same as thecharacters in the substring""" |
| 16 | if(string[i:i+end]==sub_string): |
| 17 | c=c+1 #increment counter by 1 |
| 18 | return c |
| 19 | |
| 20 | if __name__ == '__main__': |
| 21 | #strip() is used to remove leading and trailing blank spaces |