gpt4 book ai didi

python - 查找子字符串在字符串中存在的次数 - Python

转载 作者:太空宇宙 更新时间:2023-11-04 09:55:29 24 4
gpt4 key购买 nike

<分区>

我正在尝试查找子字符串的次数,在本例中,“bob”出现在字符串中。我的解决方案适用于某些字符串,但不适用于所有字符串。例如,下面的答案应该是 7,但我返回 5。

有什么想法吗?

谢谢

s = 'bobbisbobobugbobobbobbobo'
print('Number of times bob occurs is: ', s.count('bob'))

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com