题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
s=list(input()) lenth_s=len(s) num_num=0 num_f=0 num_y=0 num_zhon=0 num_k=0 for each in s: if '0'<= each <= '9': num_num+=1 if each==' ': num_k+=1 if 'a' <= each <= 'z' or 'A' <= each <= 'Z': num_y+=1 if '9' < each < 'A' or ' '< each < '0' or 'Z' < each < 'a' or each > 'z': num_f+=1 num_zhon=lenth_s-(num_f+num_k+num_y+num_num) print(num_y+num_zhon) print(num_k) print(num_num) print(num_f)
主要是记住ASC码表: