while True: msg = input("输入一段文字") if not msg:continue str_count = 0 int_count = 0 space_count = 0 special_count = 0 for i in msg: if i.isdigit(): int_count += 1 elif i.isalpha(): str_count += 1 elif i.isspace(): space_count += 1 else: special_count += 1 print(f"数字:{int_count}个,字母:{str_count}个,空格:{space_count}个,其他:{special_count}个,")
标签:count,字符,space,int,空格,str,msg,special,统计数字 From: https://www.cnblogs.com/sangern/p/17405868.html