类型一
for 循环进行数值循环
for i in range(101):
result += i
类型二
for循环遍历列表。元组,字符串,字典(用xxx表示)
for item in xxx
print(’ item =’, item)
类型三
遍历字典 values()、items() 方法的返回值
my_dic = {‘python教程’:“http://c.biancheng.net/python/”,
‘shell教程’:“http://c.biancheng.net/shell/”,
‘java教程’:“http://c.biancheng.net/java/”}
for ele in my_dic.items():
print(‘ele =’, ele)
运行结果:
ele = (‘python教程’, ‘http://c.biancheng.net/python/’)
ele = (‘shell教程’, ‘http://c.biancheng.net/shell/’)
ele = (‘java教程’, ‘http://c.biancheng.net/java/’)