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