defcount_str(strs):int_count,str_count,spa_count,other_count = 0,0,0,0
for i in strs:# 遍历字符串
if i.isdigit(): # 判断是否为数字
int_count += 1
elif i.isalnum(): # 判断是否为字母
str_count += 1
elif i.isspace(): # 判断是否为空格
spa_count += 1
else:
other_count +=1
print(“字符串s中,数字个数={},字母个数={},空格个数={},其他个数={}”.format(int_count,str_count,spa_count,other_count))
if __name__ == “__main__”:
strs = input(“请输入字符串s:”)
count_str(strs)