How to count the number of different characters in Python

藏色散人
Release: 2023-01-06 11:14:14
Original
30053 people have browsed it

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.

How to count the number of different characters in Python

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)
Copy after login

I have to marvel at the power of Python’s built-in functions

How to count the number of different characters in Python

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template