列表循环迭代

2024-05-19 01:34:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究的问题是把所有的东西都加在一起,使之成为大写。有人能给我解释一下为什么结果是“”,而没有分配像0这样的特定变量吗

sounds = ["super", "cali", "fragil", "istic", "expi", "ali", "docious"]

这是我的代码,当然不起作用:

result = 0
while result < len(sounds):
    print(sounds[result].upper)
    result += 1

以下是解决方案中提供的代码:

result = ''
for s in sounds:
    result += s
result = result.upper()

热门问题