计算字符串中某个字符的出现次数
如何计算字符串中某个字符的出现次数?
例如: 出现 4 次。'a'
'Mary had a little lamb'
如何计算字符串中某个字符的出现次数?
例如: 出现 4 次。'a'
'Mary had a little lamb'
str.count(sub[, start[, end]])
返回区域 中子字符串的非重叠出现次数。可选参数,并解释为切片表示法。
sub
[start, end]
start
end
>>> sentence = 'Mary had a little lamb'
>>> sentence.count('a')
4