Python中的for else

>>> 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部分不执行。
原文地址:https://www.cnblogs.com/nemolmt/p/6828426.html