"""
统计给定字符串中大写字母和小写字母的数量。
该函数不接受参数,也不返回任何值,但会打印出字符串中大写字母和小写字母的数量。
"""
s = 'Yalong brand is characterized by Tibet, its products include yak meat products, Tibetan cattle products, special fast-brewing tea products, yak milk products, Tibetan fragrant pig and other Tibetan agricultural products, as well as highland barley and other unique Tibetan characteristic products.'
upper = 0 # 初始化大写字母计数器
lower = 0 # 初始化小写字母计数器
# 遍历字符串中的每个字符
for item in s:
if item.isupper(): # 如果字符是大写字母
upper += 1
elif item.islower(): # 如果字符是小写字母
lower += 1
else:
pass # 忽略非大小写字母的字符
# 打印结果
print(f'大写字母有{upper}个,小写字母有{lower}个')
计算一段英文的大写字母和小写字母的数量
未经允许不得转载:创想未来 » 计算一段英文的大写字母和小写字母的数量
评论前必须登录!
注册