
上QQ阅读APP看书,第一时间看更新
3.5.1 while循环
Python中while循环语句的一般格式如下:

while循环语句同样需要注意冒号和缩进。另外,在Python中没有do...while循环。
while循环示例如下。
单击“开始”菜单,打开Python 3.6.5 Shell软件,然后在菜单栏中选择File→New File命令,创建一个Python文件,并命名为Python3-12.py,然后输入以下代码:

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

图3.19 while循环示例的运行结果