#编写函数,接收一个字符串,分别统计大写字母,小写字母,数字,其他字符的个数,并以元组的形式返回结果 |
def count_characters(input_string): |
uppercase_count = 0 |
lowercase_count = 0 |
number_count = 0 |
other_count = 0 |
for ch in input_string: |
if ch.isupper(): |
uppercase_count + = 1 |
elif ch.islower(): |
lowercase_count + = 1 |
elif ch.isnumeric(): |
number_count + = 1 |
else : |
other_count + = 1 |
return (uppercase_count, lowercase_count, number_count, other_count) |
print (count_characters( "ABCaaaaaa123456BBBbbbbbbb" )) |