How can Python calculate the number of lowercase letters?
In Python, you can use the islower() method of a string to check if a character is a lowercase letter, and calculate the number of lowercase letters by looping through the string. Here is an example:
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
Please note that the string “Hello World” in the example above contains 8 lowercase letters.