王昱棋

导航

python中的循环

python中有两种循环

1.for i in name

names=['li','wang','zhou']  #注释
for name in names:
    print(name)
sum = 0
for x in range(101):
    sum = sum + x
print(sum)

  

2.while 

sum = 0
n = 99
while n > 0:
    sum = sum + n
    n = n - 2
print(sum)

 

posted on 2019-10-28 10:41  王昱棋  阅读(178)  评论(0编辑  收藏  举报