break是跳出整个循环,continue是结束本次循环,继续执行下一个循环:
#!/usr/bin/env python # --*-- coding:utf-8 --*-- import time start = 1 while True: print("start:", start) if start == 10: break else: start += 1 if start == 5: start += 1 print("唯独缺少5") continue time.sleep(1) print("=======程序结束=======")
时间: 2024-11-05 06:23:26