python how to uppercase some characters in string

前端 未结 9 1396
北荒
北荒 2021-01-21 17:51

Here is what I want to do but doesn\'t work:

mystring = \"hello world\"
toUpper = [\'a\', \'e\', \'i\', \'o\', \'u\', \'y\']
array = list(mystring)

for c in arr         


        
9条回答
  •  借酒劲吻你
    2021-01-21 18:08

    Please try this one

    mystring = "hello world"
    toUpper = ['a', 'e', 'i', 'o', 'u', 'y']
    
    array = list(mystring)
    new_string = [x.upper() if x in toUpper else x for x in array ]
    
    
    
    new_string = ''.join(new_string)
    print new_string
    

提交回复
热议问题