# 已知字符串str='skdaskerkjsalkj',请统计该字符串中各字母出现的次数
str ='skdaskerkjsalkj'
# 从 collections 模块中导入 Counter 类
from collections import Counter
count_dict = Counter(str)
# 利用 Counter 类统计字符串中各字符的出现次数,并将结果存储在 count_dict 中
print(count_dict)
Python查找字符串中字母出现的次数
![](https://img-home.csdnimg.cn/images/20240611030827.png)