题解 | #统计字符#

统计字符

https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5

#输入字符串
str1=[x for x in input()]
letter,blank,digit,others=0,0,0,0

for x in str1:
    if x.isalpha():#检测字符是否是字母
        letter+=1
    elif x.isspace():#检测字符是否是空格
        blank+=1
    elif x.isdigit():#检测字符是否是数字
        digit+=1
    else:
        others+=1
print(letter)
print(blank)
print(digit)
print(others)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务