python how to uppercase some characters in string

前端 未结 9 1399
北荒
北荒 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:19

    The problem is that al c is not used for anything, this is not passing by reference.

    I would do so, for beginners:

    mystring = "hello world"
    toUpper = ['a', 'e', 'i', 'o', 'u', 'y']
    array = []
    for c in mystring:
        if c in toUpper:
            c = c.upper()
        array.append(c)
    print(''.join(array))
    

提交回复
热议问题