27 写函数,计算传入的字符串中【数字】、【字母】、【空格】以及【其他】的个数,并返回结果

#写函数,计算传入的字符串中【数字】、【字母】、【空格】以及【其他】的个数,并返回结果
# def func(s):
# # num = 0
# # alpha = 0
# # space = 0
# # other = 0
# dic = {'num':0,'alpha':0,'space':0,'other':0}
# for i in s:
# if i.isdigit():
# dic['num'] += 1
# elif i.isalpha():
# dic['alpha'] += 1
# elif i.isspace():
# dic['space'] += 1
# else:
# dic['other'] += 1
# return dic
# print(func('+0-0skahe817jashf wet1'))
posted @ 2018-11-04 17:54  自由自在多快乐  阅读(2263)  评论(0编辑  收藏  举报