PYTHON 写函数,计算传入字符串中【数字、字母、空格、以及其他的个数】
def func1(s): al_num = 0 spance_num = 0 digit_num = 0 others_num = 0 for i in s: if i.isdigit(): # isdigit 判断有没有数字 digit_num += 1 elif i.isspace(): # isspace 判断有没有空格 spance_num += 1 elif i.isalpha(): #isalpha 判断有没有字符 al_num += 1 else: others_num += 1 return (al_num,spance_num,digit_num,others_num) r = func1("kuh231jku ygkuhg") print(r)