求一行字符串分别求其中的字母,数字,空格,其他字符的个数`
import string
str = input("请输入字符串")
letters = 0
digit = 0
space = 0
others = 0
for s in str:
if s.isalpha():
letters+=1
elif s.isspace():
space+=1
elif s.isdigit():
digit+=1
else:
others+=1
print("字母个数为{}个".format(letters))
print("空格个数为{}个".format(space))
print("数字个数为{}个".format(digit))
print("其他字符个数为{}个".format(others))