def tongji(str):
b = str.count('[A-Z]',0,13)
l = str.count('[a-z]')
d = str.count('\d')
o = str.count('[^a-zA-Z0-9]')
test = str.count('e')
print(str,'大写字母,小写字母,数字,其他字符,test',b,l,d,o,test)
tongji('Hello world5678')
运行结果:Hello world5678 大写字母,小写字母,数字 0 0 0 0 1
可以注意到,当使用正则表达式时,返回的结果全是0,直接使用字母时返回字符串中该字母出现的次数。
然后去google了一下,count()是不接受正则表达式的 附上地址