找到大写字母

#解法一
def capitals(a):
    for index,s in enumerate(a):
        
        #isupper 如果字符串中都是大写,返回True,如果有一个小写,返回False
        
        if s.isupper():
            print(index)

capitals('anMIE')
#解法二
def capitals(word):
    capitals_index=[]
    for i in range(len(word)):
        if word[i].isupper():
            capitals_index.append(i)
            
    return capitals_index

print(capitals('CodEWaRs'))
#解法三
def capitals(word):
    return [i for i,s in enumerate(word) if 'A' <= s <= 'Z']
    
capitals('CodEWaRs')

相关文章:

  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-02-02
  • 2022-01-01
猜你喜欢
  • 2021-11-23
  • 2022-02-06
  • 2021-12-03
  • 2021-08-03
  • 2022-12-23
  • 2021-12-28
相关资源
相似解决方案