groups = [["Roy","Sam","Amy"],["Tom","Jerry"]]
尝试理解我从此代码中获得的输出
for group in groups:
for name in group:
print(group)
['Roy', 'Sam', 'Amy']
['Roy', 'Sam', 'Amy']
['Roy', 'Sam', 'Amy']
['Tom', 'Jerry']
['Tom', 'Jerry']
答案 0 :(得分:1)
好像你打算打印name
(内部列表中的元素),而不是group
(内部列表本身):
>>> groups = [["Roy","Sam","Amy"],["Tom","Jerry"]]
>>> for group in groups:
... for name in group:
... print(name)
...
Roy
Sam
Amy
Tom
Jerry