[73.Python高级(7):多样化遍历] 零基础学python,简单粗暴

反向遍历

# 反向遍历
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’

版权声明:本文为博主原创文章,未经博主允许不得转载。https://my.csdn.net/pangzhaowen

猜你喜欢

转载自blog.csdn.net/pangzhaowen/article/details/80721920
今日推荐