码迷,mamicode.com
首页 > 编程语言 > 详细

python学习:for else语句

时间:2015-01-29 21:09:30      阅读:450      评论:0      收藏:0      [点我收藏+]

标签:python   for-else   

1:先看例子


看输出结果:
1
2
3
4
all number is positive

2:再看一个变例

看输出结果:
1
2


3:结论

当for语句中没有执行break的话,遍历完for语句,就会执行else语句
但是如果中间执行了break语句,跳出for循环,那么不会执行else语句。




python学习:for else语句

标签:python   for-else   

原文地址:http://blog.csdn.net/u013628152/article/details/43276857

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!