循环使用 else 语句
在 python 中,while … else 在循环条件为 false 时执行 else 语句块:
实例
#!/usr/bin/pythoncount = 0whilecount < 5: printcount, " is less than 5" count = count + 1else: printcount, " is not less than 5"
以上实例输出结果为:
0is less than 5
1is less than 5
2is less than 5
3is less than 5
4is less than 5
5isnot less than 5