
上QQ阅读APP看书,第一时间看更新
3.5.2 while循环使用else语句
在while…else语句中,如果条件语句为False时,则执行else的语句块。
while循环使用else语句示例如下。
单击“开始”菜单,打开Python 3.6.5 Shell软件,然后在菜单栏中选择File→New File命令,创建一个Python文件,并命名为Python3-13.py,然后输入以下代码:

在菜单栏中选择Run→Run Module命令或按键盘上的F5键,就可以运行程序代码,结果如图3.20所示。

图3.20 while循环使用else语句示例的运行结果