📅  最后修改于: 2022-03-11 14:46:04.050000             🧑  作者: Mango
pythonCopy#defining string and substring
str1 = "This dress looks good; you have good taste in clothes."
substr = "good"
#occurrence of word 'good' in whole string
count1 = str1.count(substr)
print(count1)
#occurrence of word 'good' from index 0 to 25
count2 = str1.count(substr,0,25)
print(count2)