七、流程控制之for循环

for循环主要用于循环取值

students=['张三','李四','王五','陈一','黄二']

i=0
while i < len(students):
    print(students[i])
    i+=1

for item in students:
    print(item)

for item in 'hello':
    print(item)

dic={'x':444,'y':333,'z':222}
for k in dic:
    print(k,dic[k])


for i in range(1,10,3):#其中3为步长
    print(i)

for i in range(10):#range中启始值默认为0,步长默认为1
    print(i)

student=['张三','李四','王五','陈一','黄二']

for i in range(len(student)):
    print(i,student[i])

 

posted @ 2018-09-14 15:38  Maple_feng  阅读(906)  评论(0编辑  收藏  举报