美文网首页python笔记
Python迭代列表

Python迭代列表

作者: GarveyLian | 来源:发表于2017-08-06 17:54 被阅读4次
    处理列表中的每一项是一个非常常见的需求,如何在python中快速的处理列表的迭代呢?
    movies=["The Holy Grail",1975,"The Life of Brian",1979,"The Meaning of Life",1983]
    for each_item in movies:
      print(each_item)
    

    语法如下
    for 目标标识符 in 列表
    列表处理代码

    还有一种候选写法,用while写

    count=0
    while count<len(movies):
      print(movies[count])
      count=count+1
    

    基本上都是选择for循环

    相关文章

      网友评论

        本文标题:Python迭代列表

        本文链接:https://www.haomeiwen.com/subject/gshnlxtx.html