Github base demo 07
""" base 07 写函数,计算传入字符串中【数字】、【字母】、【空格] 以及 【其他】的个数 """ def demo(s): d = 0 a = 0 s = 0 e = 0 st = input('输入字符串') for i in st: if i.isdigit() is True: d += 1 elif i.isalnum() is True: a += 1 elif i.isspace() is True: s += 1 else: e += 1 print('数字:{}\n字母:{}\n空格:{}\n其他:{}\n'.format(d, a, s, e)) return demo(s) demo('')