反向遍历
# 反向遍历
mlist = [1, 2, 3]
for item in reversed(mlist):
print(item)
执行结果:3,2,1
组合遍历
# 组合遍历
mlist = [1, 2, 3]
ylist = ["a", "b", "c"]
for m, y in zip(mlist, ylist):
print(m, y)
执行结果:1,‘a’ 2,’b’ 3,’c’
带序号的遍历
# 加序号遍历
ylist = ["a", "b", "c"]
for i, x in enumerate(ylist):
print(i, x)
执行结果:0,‘a’ 1,’b’ 2,’c’