python中如何只用一个循环遍历3个名称不同的数组
可以使用zip函数来遍历三个数组,例如:
array1 = [1, 2, 3]
array2 = ['a', 'b', 'c']
array3 = [True, False, True]
for a, b, c in zip(array1, array2, array3):
print(a, b, c)
输出:
1 a True
2 b False
3 c True
在这个循环中,zip函数将三个数组打包为一个元组的列表,然后我们可以使用多个变量来解压每个元组,并在循环中使用它们。
原文地址: http://www.cveoy.top/t/topic/bO4N 著作权归作者所有。请勿转载和采集!