Python编程统计字符串内元素类型的个数

答案:

intCount=0
strCount=0
otherCount=0
a=input('Please input a string:')
for i in a:
    if i.isdigit():
        intCount +=1
    elif i.isalpha():
        strCount +=1
    else:
        otherCount +=1
print('数字=%d,字母=%d, 其他=%d' %(intCount,strCount,otherCount))

如果答案,您满意,请采纳意见和点赞关注,支持一下,谢谢!

你可能感兴趣的:(Python,python)