【Python】输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数
·
s=input('请输入内容:')
letter=0
space=0
digit=0
other=0
for i in s:
if i.isalpha():#判断是否是字母
letter+=1
elif i.isspace():#判断是否是空格
space+=1
elif i.isdigit():#判断是否是数字
digit+=1
else:
other+=1
print('字母个数为{},空格字数为{},数字字数为{},其他字符为{}'.format(letter,space,digit,other))
更多推荐
所有评论(0)