Python语言基础 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

while语句


在 python 中,while … else 表示这样的意思,while 中的语句和普通的没有区别,else 中的语句会在循环正常执行完的情况下执行。其格式如下:

while 判断条件:
      语句组
else:
      语句组
count = 0
while count < 5:
     print count, " is  less than 5"
     count = count + 1
else:
     print count, " is not less than 5"