在此代码中,程序计算bob的名称在字符串s
s = 'tobooboboboboboobooxbobbs'
count = 0
for name in "bob":
if name in s:
count += s.count(name)
print("Number of times bob occurs is: " + str(count))
我希望看到这样的输出:
Number of times 'bob' occurs is: 5
但我得到了:
Number of times bob occurs is: 32
为什么呢?我如何解决它?点的平均值是什么:.
中的s.count(name)
?