count = 0
flag = True
start = 0
while flag:
    a = nStr.find(pattern, start)
if a == -1:
    flag = False
else:
    count += 1
start = a + 1
print(count)
Determining how many times a substring occurs in a string in Python