[英]Find how many times string appears in another python
python 中是否有一種方法可以檢查一個字符串在另一個字符串中出現的次數? 例如
a="1ab1"
new_string="1ab1ab1ab1"
我應該得到 3 但我用 str.count() 得到了 2
謝謝
使用string.count()
function:
a="aba"
new_string="aba3abaa"
cnt = new_string.count(a)
print(cnt)
Output: 2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.