字符串练习
def func(s): dic = {'num': 0, 'alpha': 0, 'space': 0, 'other': 0} for char in s: if char.isdigit(): dic['num'] += 1 elif char.isalpha(): dic['alpha'] += 1 elif char.isspace(): dic['space'] += 1 else: dic['other'] += 1 return dic print(func("s100www:// 3vv- w2jfk"))

浙公网安备 33010602011771号