Python遍历列表的四种方式

方式一:


app_list = [1234, 5677, 8899]

for app_id in app_list:

    print app_id

输出: 
1234 
5677 
8899

方式二:


app_list = [1234, 5677, 8899]

for index,app_id in enumerate(app_list):

    print index, app_id

输出: 
0 1234 
1 5677 
2 8899

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


 app_list = [1234, 5677, 8899]

    for i in range(len(app_list)):

          print i,app_list[i]

输出: 
0 1234 
1 5677 
2 8899

方式四: 使用iter()


app_list = [1234, 5677, 8899]

for app_id in iter(app_list):

    print app_id

输出: 
1234 
5677 
8899


你可能感兴趣的:(Python,python,列表)