How can I count the number of times a given substring is present within a string in Python?
For example:
>>> \'foo bar foo\'.numberOfOccurre
s = input('enter the main string: ') p=input('enter the substring: ') l=[] for i in range(len(s)): l.append(s[i:i+len(p)]) print(l.count(p))