python: for else

上一篇 / 下一篇  2014-07-06 22:43:16 / 个人分类:Python

for i in range(0,10):
        if i > 10:
            break;
    else:
        print "hello world";
输出:hello world
>>> for i in range(0,10):
        if i > 5:
            break;
    else:
        print "hello world";
没有输出
-------------------
即在for 循环中,如果没有从任何一个break中退出,则会执行和for对应的else
只要从break中退出了,则else部分不执行。


TAG:

 

评分:0

我来说两句

Open Toolbar