Python While 循环语句使用else语句
语法:
while 判断条件:
代码块1
else:
代码块2
说明:
当判断条件为true时,执行代码块1,否则执行else后的代码块2
示例:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 定义变量,通过赋值运算符赋值“=”
count = 0;
# 当count值小于9时输出当前count的值,count大于9后进入else部分
while count < 9:
count += 1;
print 'current is: ',count;
else:
print 'exit while';
print 'the end';
代码截图:
运行截图:
查看更多技术请移步:https://ui.29mn.com
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。