1 mystring = input(‘输入一带有字母数字特殊符号的字符串:‘) 2 alpha = 0 3 space = 0 4 number = 0 5 other = 0 6 for i in mystring: 7 if i >= ‘a‘ and i <= ‘z‘ or i >= ‘A‘ and i <= ‘Z‘: 8 alpha += 1 9 elif i >= ‘0‘ and i <= ‘9‘: 10 number += 1 11 elif i.isspace(): 12 space += 1 13 else: 14 other += 1 15 print(‘alpha:{},number:{},space:{},other:{}‘.format(alpha,number,space,other))
原文:https://www.cnblogs.com/reaix/p/12670995.html