Python实训2 统计字符串内元素类型的个数

在这里插入图片描述
在这里插入图片描述
答案源码:

intCount,strCount,otherCount = 0,0,0
string = input("请输入任意字符串:")
for i in string:
    if(i.isdigit()):
        intCount+=1
    elif(i.isalpha()):
        strCount+=1
    else:
        otherCount+=1
print("intCount:{},strCount:{},otherCount:{}.".format(intCount,strCount,otherCount))

运行结果:
在这里插入图片描述

答案拿走,随手留下你的赞~

欢迎关注公众号【夜来疏影】,与你分享生活
在这里插入图片描述

发布了89 篇原创文章 · 获赞 207 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43729943/article/details/105219953
今日推荐