Python_Python遍历列表的四种方法

方式一:


app_list = [1234, 5677, 8899]
<!-- lang: python -->
for app_id in app_list:
<!-- lang: python -->
    print app_id

输出: 
1234 
5677 
8899

方式二:


app_list = [1234, 5677, 8899]
<!-- lang: python -->
for index,app_id in enumerate(app_list):
<!-- lang: python -->
    print index, app_id

输出: 
0 1234 
1 5677 
2 8899

方式三: 使用range()或xrange()


 app_list = [1234, 5677, 8899]
<!-- lang: python -->
    for i in range(len(app_list)):
<!-- lang: python -->
          print i,app_list[i]

输出: 
0 1234 
1 5677 
2 8899

方式四: 使用iter()


app_list = [1234, 5677, 8899]
<!-- lang: python -->
for app_id in iter(app_list):
<!-- lang: python -->
    print app_id

输出: 
1234 
5677 
8899

posted @ 2016-12-25 21:32  Beeman_xia  阅读(1439)  评论(0编辑  收藏  举报