By
Moky
Updated:
原创作品,允许转载。转载时请务必以超链接形式标明文章原始出处、作者信息和本声明,否则将追究法律责任。
方法一
1 2
| s = "abacad" print s.count("a")
|
方法二
1 2 3
| import re count = len(re.findall("a","abacad")) print(count)
|
方法三
1 2 3 4
| from collections import Counter s = "abacad" c = Counter(s) print c['a']
|
方法四
1
| print len([ele for ele in 'abacad' if ele == 'a'])
|