学习:python 了解循环

循环结构

for 循环

for x in range(1,10):
    print("hellow")

for循环

#遍历容器

#将容器或序列中的数据一个一个取出来

for x in 列表名:

  print()

#直接遍历

names = ["张三","李四","王五","李留","王二麻子"]

for x in names:

  if x =="王五"

    pirnt("有这个人")

#构造索引
for i in range(0,len(names)):
    print(names[i])
#元组
scores = (67,68,69,70,71)
    for score in scores:
        print(score)
for i in range(0,len(scores)):
    print(score)
#平均分
total = 0
for i in range(0,len(scores)):
    total = total+score
    print(total/len(scores))
#如果用循环遍历字典,只能获取到键
for x in 字典名:
    pring(x,字典名[x])

写for循环要弄清楚 循环操作是什么?循环次数是?

所有循环语句和for之间都有一个缩进

posted @ 2022-07-28 14:08  测试小潘  阅读(28)  评论(0)    收藏  举报