Skip to main content
 首页 » 编程设计

python之如何在 python 中同时运行 2 个列表

2025年05月04日9zfyouxi

<分区>

我正在尝试依次打印 2 个列表中的内容。

ls1 = ['Apple', 'Orange', 'Banana', 'Morty'] 
ls2 = ['Pineapple', 'Carrot', 'Rick', 'Tangelo'] 

我通常会这样做:

for fruit in ls1: 
    print(fruit) 
for fruit in ls2 
    print(fruit) 

但这将循环通过一个列表然后另一个。我希望输出按顺序在列表之间交替:

Apple 
Pineapple 
Orange 
...etc... 

或

ls1[0] 
ls2[0] 
ls1[1] 
ls2[1] 
...etc...