【发布时间】:2018-01-08 22:14:32
【问题描述】:
我正在学习 python,并通过一个实际示例遇到了一个我似乎无法找到解决方案的问题。
我使用以下代码得到的错误是
'list' object has to attribute 'upper'。
def to_upper(oldList):
newList = []
newList.append(oldList.upper())
words = ['stone', 'cloud', 'dream', 'sky']
words2 = (to_upper(words))
print (words2)
【问题讨论】:
-
从不同的答案可以看出,有很多方法可以做到这一点。这是另一种方式,将
to_upper函数中的最后一行替换为这两行newList.extend([o.upper() for o in oldList]); return newList
标签: python-3.x uppercase