dic = { 'number': 0, 'letter': 0, 'space': 0, 'other': 0 } def hao(info): if type(info) == str: for i in info: if i.isdigit(): dic['number'] += 1 elif i.isalpha(): dic['letter'] += 1 elif i.isspace(): dic['space'] += 1 else: dic['other'] += 1 else: print('请输入字符串') exit() print(dic) hao('123123== ')
python写函数,计算传入字符串中【数字】、【字母】、【空格] 以及 【其他】的个数
猜你喜欢
转载自www.cnblogs.com/haoxiaobai/p/9366905.html
今日推荐
周排行