Python统计字符出现次数

来源:互联网 发布:js如何设置按钮 编辑:程序博客网 时间:2024/06/06 03:30
# -*- coding:utf-8 -*-def alpa(string):    a = 0    b = 0    c = 0    d = 0    count=0    while(string[count]!='\n'):        if ((string[count] <= 'z' and string[count] >= 'a') or (string[count] <= 'Z' and string[count] >= 'A')):            a += 1        elif (string[count] <= '9' and string[count] >= '0'):            b += 1        elif (string[count] == ' '):            c += 1        else:            d += 1        count+=1    print a, b, c, daa="abch +  7+\n"alpa(aa)