好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python for ,loop ,else condition test

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 for ,loop ,else condition test的详细内容...

  阅读:45次