赞
踩
1.for循环是遍历列表和元组,而while循环只要循环不满足,则会结束循环
#for..in循环,遍历列表和元组 list1 = [1,2,3,4,5] for i in list1: print(i) tuple1 = (1,2,3,4,5) for m in tuple1: print(m) #运行结果:1 2 3 4 5 #运行结果:1 2 3 4 5 #while循环,只要条件满足就会不断循环,直到不满足,结束循环 sum = 0 n = 100 while n >0 : sum +=n n -=1 print(sum) #运行结果:5050
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。