How python counts the number of different characters
This article introduces the relevant knowledge of "how to count different characters in python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The operating environment of this tutorial: windows7 system, Python 3.9.1 Dell G3 computer.
1. Statistical process
The most important thing is to find a standard to use if sentences to distinguish the characters that need to be counted. Obviously, python3.X can use unicode directly.
Determine the unicode coding range, including Chinese characters, numbers, lowercase letters and uppercase letters.
Make sure there is only one line of output.
Write the code.
2. Examples
N=input ("Please enter a line of characters:") # enter a line of characters a=b=c=d=0#an is the number of letters, b is the number of numbers, c is the number of spaces, d is the number of other characters for i in n:#for loop traversal string n#ord () built-in function, returns the corresponding ASCII value if ord ('a')