首页 > 编程语言 > 详细

Python List数据的遍历

时间:2014-10-17 17:03:24      阅读:330      评论:0      收藏:0      [点我收藏+]

方式一:

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

Python List数据的遍历

原文:http://my.oschina.net/syc2013/blog/333265

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!