python: for i in zip() implements parallel traversal in python

The zip() function is used to pack the elements at the corresponding positions of the two lists into a tuple.

1. The number of elements in the two lists is the same:

A=[1,2,3,4]
B=['吕布',‘司空震’,‘蒙恬’,‘马超’]
for i in zip(A,B):
	print(i)

insert image description here

2. The elements in the two lists are different: (the length of the return value is the same as the length of the list with fewer elements)

A=[1,2,3,4]
B=['吕布',‘司空震’,‘蒙恬’,‘马超’,‘凯’]
for i in zip(A,B):
	print(i)

insert image description here

Guess you like

Origin blog.csdn.net/fengbao24/article/details/125456284