题目描述
代码实现
str_input = input()
for i in range(10):
if str_input.count(str(i))!=0:
print("%d:%d"%(i,str_input.count(str(i))))
知识点总结
因为python有count()函数,所以这道题就简单了起来~
- count()方法语法:
str.count(sub, start= 0,end=len(string))
- 参数
sub – 搜索的子字符串
start – 字符串开始搜索的位置。默认为第一个字符,第一个字符索引值为0。
end – 字符串中结束搜索的位置。字符中第一个字符的索引为 0。默认为字符串的最后一个位置。