温馨提示×

Python中怎么遍历多个列表

小亿
109
2024-05-10 15:07:15
栏目: 编程语言
Python开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在Python中可以使用`zip`函数来同时遍历多个列表,例如:

```python

list1 = [1, 2, 3]

list2 = ['a', 'b', 'c']

list3 = ['x', 'y', 'z']

for item1, item2, item3 in zip(list1, list2, list3):

print(item1, item2, item3)

```

上面的代码会输出:

```

1 a x

2 b y

3 c z

```

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:Python中怎么遍历列表

0