import re def calcultor(content): num = len(re.findall(‘[0-9]‘,content)) alpah = len(re.findall(‘[a-zA-Z]‘,content)) blank = len(re.findall(‘ ‘,content)) others = len(re.findall(‘[^0-9a-zA-Z ]‘,content)) print(‘数字:%s , 字母:%s ,空格:%s,其他:%s‘%(num,alpah,blank,others)) calcultor(‘a s****-‘) #数字:0 , 字母:2 ,空格:2,其他:5
原文:https://www.cnblogs.com/thanos-ryan/p/13744443.html