题解 | #统计字符#

统计字符

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

s = input()
letter_count = 0
number_count = 0
blank_count = 0
other_count = 0

for char in s:
    # isalpha函数判断是否字母
    if char.isalpha():
        letter_count += 1
    # isnumeric函数判断是否数字
    elif char.isdigit():
        number_count += 1
    # isspace函数判断是否空格
    elif char.isspace():
        blank_count += 1
    # 其他情况继续+1
    else:
        other_count += 1
print(letter_count)
print(blank_count)
print(number_count)
print(other_count)

考察字符串的常用内置方法:
str.isalpha()判断元素是不是字母

str.isdigit()判断元素是不是数字

str.isspace() 判断元素是不是空格
#数据仓库与数据分析实习#
OD专栏练习梳理 文章被收录于专栏

OD专栏练习梳理

全部评论

相关推荐

真烦好烦真烦:豆包润色了自己没看看吗,再说了,都说豆包是愚蠢且勤快的大学生,ds才是聪明的研究生,怎么敢让豆包写论文的
你们的毕业论文什么进度了
点赞 评论 收藏
分享
鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
练习生懒羊羊:开飞机把这个公司创飞吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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