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

               
s=input('input a string:\n')letters=0space=0digit=0others=0for c in s:    if c.isalpha():        letters+=1    elif c.isspace():        space+=1    elif c.isdigit():        digit+=1    else:        others+=1print('char=%d,space=%d,digit=%d,others=%d'%(letters,space,digit,others))

运行结果:

input a string:

gkjtrlkhgq  43678 ';m,2345gf erwhy

char=18,space=5,digit=9,others=3


           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/qq_43667626/article/details/86310097