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])

 

相关文章:

  • 2021-10-29
  • 2022-12-23
  • 2021-12-30
  • 2021-11-14
  • 2021-05-02
  • 2021-12-24
  • 2022-12-23
猜你喜欢
  • 2021-10-11
  • 2021-12-15
  • 2021-04-04
  • 2021-12-18
  • 2021-06-04
相关资源
相似解决方案