📌  相关文章
📜  python 查找字符串中所有出现的地方 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:04.050000             🧑  作者: Mango

代码示例1
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)