我试图使用while循环从python中的列表中读取内容,但似乎无法获得它。我不断得到列表索引超出范围的错误。你知道吗
以下是列表:
names = [['Bilbo', 'Baggins'], ['Gollum'], ['Tom', 'Bombadil'], ['Aragorn']]
而不是使用for循环:
for person in people:
to_print = ""
for name in person:
to_print += name + " "
print(to_print)
Tags:
要使用Python列表,不需要索引。你知道吗
像这样的怎么样?你知道吗
您的
for
循环代码的等效while
循环版本是:更好的
for
循环代码是:相关问题 更多 >
编程相关推荐