How to extract all UPPER from a string? Python

后端 未结 7 2105
终归单人心
终归单人心 2020-12-31 04:51
#input
my_string = \'abcdefgABCDEFGHIJKLMNOP\'

how would one extract all the UPPER from a string?

#output
my_upper = \'ABCDEFGHIJKL         


        
7条回答
  •  無奈伤痛
    2020-12-31 05:22

    here you go:

    my_string = 'abcdefgABCDEFGHIJKLMNOP'
    
    cleanChar = ''
    
    for char in my_string:
        if char in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
            cleanChar = cleanChar + char
    
    newChar = cleanChar
    print(" {}".format(newChar))
    

提交回复
热议问题