制作一个count字符串工具,
def countStr(object): Num = 0 Alpha = 0 space = 0 other = 0 for i in object : if i.isdigit():#是否数字 Num+=1 elif i.isalpha():#是否字母 Alpha+=1 elif i.isspace():#是否空格 space+=1 else:#其他 other+=1 print ('数字有%d个,字母有%d个,空格有%d个,其他有%d个' % (Num, Alpha, space, other)) a=countStr('asdfgasdfg asdf')