用Python输入一个字符串,统计输入的字符串中数字、大写字母、小写字母、其他字符的个数,并输出!
·
1.str.isupper()#用来判断是否为大写字母
2.str.islower()#用来判断是否为小写字母
3.str.isdigit#用来判断是否为数字
count1,count2,count3,count4=0,0,0,0
string=input("请输入一个字符串:")
for s in string:
if s.isupper():
count1+=1
elif s.islower():
count2+=1
elif s.isalnum():
count3+=1
else:
count4+=1
print("大写字母有:"+str(count1)+"\t"+"小写字母有:"+str(count2)+"\t"+"数字有:"+str(count3)+"\t"+"其他字符有:"+str(count4))
更多推荐
已为社区贡献2条内容
所有评论(0)