python统计不同字符的个数的方法:首先创建一个py示例文件;然后通过“for i in str:resoult[i]=str.count(i)”方法统计不同字符的个数即可。

本文操作环境:windows7系统、python3.6.4版、Dell G3电脑。

Python--统计字符串中各字符的个数

#统计字符个数
str=input("请输入一串字符:")
resoult={}
for i in str:
    resoult[i]=str.count(i)
print(resoult)

不得不惊叹Python内置函数的强悍

069c299a207c1c1b8277df0e6e8c002.png

相关免费学习

python怎么统计不同字符的个数