python for ,loop ,else condition test

when you use break jump out from for or while statement,if has else caluse,it will not exec,
for example:
>>> for i in xrange(0,11):
    print i
else:
    print "haha,%s"%i

   
0
1
2
3
4
5
6
7
8
9
10
haha,10
>>> for i in xrange(0,11):
    print i
    if i>7:
        print "jump"
        break
else:
    print "haha,%s"%i

   
0
1
2
3
4
5
6
7
8
jump
>>>


你可能感兴趣的:(python)