一、for
if __name__ == '__main__': # 确定循环,range产生一个序列[0,1,2] for i in range(3): print(i) #换行 print("列表") # 遍历里诶包 for i in [2, 4, 6]: print(i) print("步长为2") # range产生序列,从1开始不包含11,步长为2 for i in range(1,11,2): print(i) print("跳过5") for i in range(7): if i==5: continue; print(i) print("中断5") for i in range(7): if i == 5: break; print(i)
0 1 2 列表 2 4 6 步长为2 1 3 5 7 9 跳过5 0 1 2 3 4 6 中断5 0 1 2 3 4
二、while
if __name__ == '__main__': num = 10; while num <= 10: num = num + 1 print(num)
11