你可以使用Python的内置方法islower()
和count()
来统计字符串中小写字母的个数。下面是一个示例代码:
def count_lowercase(string):
count = 0
for char in string:
if char.islower():
count += 1
return count
# 示例用法
string = "Hello World"
lowercase_count = count_lowercase(string)
print(lowercase_count)
运行这段代码,输出结果为:
8
这表示字符串中包含8个小写字母。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>