Example1:
-- coding: utf-8 --
s = 'azcbobobegghakl'
num = 0
for i in range(len(s)):
num += s[i:i+3].count('bob')
print 'Number of times bob occurs is: %s' % num
Example2:
s = 'azcbobobegghakl'
bobn=0
x=0
while True:
if s.find("bob",x)!=-1:
bobn+=1
x=s.find("bob",x)+1
else:
break
print("Number of times bob occurs is: "+str(bobn))