for in zip
时间: 2023-07-12 10:21:23 浏览: 55
`for in zip` is a Python syntax that allows you to iterate over multiple iterables in parallel. It is commonly used when you have two or more lists of equal length and you want to loop through them simultaneously, matching the elements at corresponding indexes.
Here's an example:
```
list1 = [1, 2, 3]
list2 = ['a', 'b', 'c']
for num, letter in zip(list1, list2):
print(num, letter)
```
Output:
```
1 a
2 b
3 c
```
In the above code, `zip` takes two iterables `list1` and `list2` and returns an iterator that produces tuples of corresponding elements from both lists. The `for in` loop then iterates over these tuples and unpacks them into the variables `num` and `letter` for each iteration.