16 复习一下format格式化输出

 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))

 

posted @ 2020-04-10 07:47  不着魔,不成佛  阅读(150)  评论(0编辑  收藏  举报