我正在学习python和一个实际的例子,我遇到了一个问题,我似乎无法找到解决方案。 我用下面的代码得到的错误是 'list' object has to attribute 'upper'
。使列表中的字符串大写 - Python 3
def to_upper(oldList):
newList = []
newList.append(oldList.upper())
words = ['stone', 'cloud', 'dream', 'sky']
words2 = (to_upper(words))
print (words2)
,你可以通过不同的答案告诉有很多方法可以做到这一点。这里只是另一种方法,用'newList.extend(oldList中的o [oper()for o)]来替换'to_upper'函数中的最后一行。 return newList' – davedwards