Count the uppercase letters in a string with Python

前端 未结 8 2014
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 10:25

I am trying to figure out how I can count the uppercase letters in a string.

I have only been able to count lowercase letters:

def n_lower_chars(st         


        
8条回答
  •  没有蜡笔的小新
    2021-01-01 10:28

    def n_lower_chars(string):
        return sum(i.isupper() for i in string)
    

    sums up the numbers of True values in the generator expression

提交回复
热议问题