用python如何优雅的判断一个字符串里有多少大写字母,小写字母,中文,标点符号,数字?

import re
s = input('输入一串字符:')
char = re.findall(r'[a-z]',s)
bigchar= re.findall(r'[A-Z]',s)
num = re.findall(r'[0-9]',s)
blank = re.findall(r' ',s)
#\u4E00-\u9FFF是中文的范围
chi = re.findall(r'[\u4E00-\u9FFF]',s)
other = len(s)-len(char)-len(bigchar)-len(num)-len(blank)-len(chi)
print("小写字母:", len(char),"\n大写字母:",len(bigchar),"\n数字:", len(num),"\n空格:",len(blank),"\n中文:",len(chi),"\n其他:",other)

大佬问的问题,记录一下怎么解决D

用python如何优雅的判断一个字符串里有多少大写字母,小写字母,中文,标点符号,数字?_第1张图片

你可能感兴趣的:(Python学习)