import stringdef SlowSnail(s):up = 0low = 0space = 0digit = 0others = 0for c in s:if c.isupper():up += 1elif c.islower():low += 1elif c.isspace():space += 1elif c.isdigit():digit += 1else:others += 1print('大写字母 = %d,小写字母 = %d,空格 = %d,数字 = %d,其他 = %d' % (up, low, space, digit, others))while 1:s = input('请输入一个字符串:\n')if '-1' in s: # 设置退出循环条件breakSlowSnail(s) # 调用函数
如果觉得《Python输入一行字符 分别统计出其中大小写英文字母 空格 数字和其它字符的个数。》对你有帮助,请点赞、收藏,并留下你的观点哦!