2018.09.14python学习第四天part3
流程控制之for循环
for循环主要用于循环取值
取列表:m=[1,2,3,4,5,6,7,8]
#用while循环取值
i=0 while i<len(m): print(i) i+=1
#用for循环取值
for i in m: print(i)
取字典:m={"x":4,"y":5,"z":6}
#用for取值
for k in m: print(k,dic[k])
ps:
for a in range(1,10,2): print(a)
表示从1到10之中没隔2取一个值,顾头不顾尾