Home>Article>Backend Development> How to count the number of different characters in Python
How to count the number of different characters in python: first create a py sample file; then count the number of different characters through the "for i in str:resoult[i]=str.count(i)" method That’s it.
The operating environment of this article: Windows 7 system, python version 3.6.4, Dell G3 computer.
Python--Counting the number of characters in a string
#统计字符个数 str=input("请输入一串字符:") resoult={} for i in str: resoult[i]=str.count(i) print(resoult)
I have to marvel at the power of Python’s built-in functions
Related free Learning recommendation:python video tutorial
The above is the detailed content of How to count the number of different characters in Python. For more information, please follow other related articles on the PHP Chinese website!