字符串--统计个数

输入一行非中文字符,分别统计出其中英文字母、空格、数字和其他字符的个数

def countzimu():
    dict = {}
    shuzi = 0
    zimu = 0
    space = 0
    other = 0
    str = input("请输入任意字符:")
    for i in str:
        if i.isdigit():
            shuzi+=1
        elif i.isalpha():
            zimu+=1
        elif i.isspace():
            space+=1
        else:
            other+=1
    dict['shuzi'] = shuzi
    dict['zimu'] = zimu
    dict['space'] = space
    dict['other'] = other
    return dict
print(countzimu())

  

posted @ 2021-11-23 08:48  呆呆蒙蒙  阅读(201)  评论(0编辑  收藏  举报