Statistics of the number of letters, numbers, and spaces in a string

Feel free to post one to bring life to my blog. I am thinking about how to get rid of the basics and write 666. . .

n = input('请输入内容:\n')
a = 0
b = 0
c = 0 
d = 0
for i in n:
    if i.isalpha():
        a += 1
    elif i.isspace():
        b += 1
    elif i.isdigit():
        c += 1
    else:
        d += 1
print('字符={}个,空格= {}个 ,数字={}个 ,其他={}个'.format(a,b,c,d))

Guess you like

Origin blog.csdn.net/qq_43254543/article/details/104723167