以下代码:
list1=['hello','bye']
list2=['john','dave','joe','bob']
for say in range (2):
print list1[say]
for name in range (4):
print list2[name]
结果是:
hello
bye
john
dave
joe
bob
如何安排代码,结果如下:
hello
john
dave
joe
bob
bye
john
dave
joe
bob
我是编码的新手。谢谢你的帮助
答案 0 :(得分:1)
list1=['hello','bye']
list2=['john','dave','joe','bob']
for listitem1 in list1:
print(listitem1)
for x in list2:
print(x)
答案 1 :(得分:0)
只需迭代列表,就更容易了:
list1=['hello','bye']
list2=['john','dave','joe','bob']
for say in list1:
print(say)
for name in list2:
print(name)