python 输出字符串中每个字符的个数
#输出每个字符的个数, 则需要展示字符名称 , 和值, 则需使用字典
def str_c(st):
dic = {}
i = 0
while i < len(st):
if st[i] in dic:
dic[st[i]] += 1
else:
dic[st[i]] = 1
i += 1
for tm in dic.items():
print(tm)
if __name__ == "__main__":
s = 'sklhsss2klj'
str_c(s)

浙公网安备 33010602011771号