在Python 3.4.3中,如何将列表中的字符串更改为大写?

在Python 3.4.3中,如何将列表中的字符串更改为大写?,python,list,Python,List,当我尝试添加 [x.upper() for x in b] 什么也没发生。我知道 x.upper() 不是列表的intendef,但也许它可以以某种方式实现。这不是我的家庭作业 import random a = ["po", "ko", "do", "to"] b = ["ab", "cd", "ef", "gh"] [x.upper() for x in b] def ran(): for i in range(0,1): random.shuffle(a)

当我尝试添加

[x.upper() for x in b] 
什么也没发生。我知道

x.upper() 
不是列表的intendef,但也许它可以以某种方式实现。这不是我的家庭作业

import random

a = ["po", "ko", "do", "to"]
b = ["ab", "cd", "ef", "gh"]

[x.upper() for x in b]

def ran():

for i in range(0,1):
    random.shuffle(a)
    print(a[0], "\n", a[1], "\n", a[2], "\n", a[3])


for y in range(0,1):
    random.shuffle(b)
    print(b[0], "\n", b[1], "\n", b[2], "\n", b[3])

您的列表理解将生成一个列表。如果希望更改原始列表,则需要将其重新分配到原始列表
b
。它不进行就地修改

b = [x.upper() for x in b]
b = [x.upper() for x in b]
声明

[x.upper() for x in b]
只会返回一个新列表

您必须将其指定给某个变量作为