# 统计一个字符串中字母、数字及其他字符的个数,返回一个元组 def tongji(s): count1 = 0 count2 = 0 count3 = 0 for i in range(len(s)): if (s[i] >= 'a' and s[i] <= 'z') or (s[i] >= 'A' and s[i] <= 'Z'): count1 = count1 + 1 elif (s[i] >= '0' and s[i] <= '9'): count2 = count2 + 1 else: count3 = count3 + 1 return (count1,count2,count3) s = input("请输入一个字符串:") print(tongji(s))
python 统计一个字符串中字母、数字及其他字符的个数,返回一个元组
最新推荐文章于 2022-07-20 20:43:53 发布