# while中使用else>>> L =list(range(10))>>>whilelen(L)>=1:
tmp = L.pop()print(tmp)else:print("exit while")9876543210
exit while>>># for 中使用 else>>>for digit inrange(10):print('the number is: {digit}'.format(digit = digit))else:print("exit for")
the number is:0
the number is:1
the number is:2
the number is:3
the number is:4
the number is:5
the number is:6
the number is:7
the number is:8
the number is:9
exit for>>>
break会跳过else子句
>>> L =list(range(10))>>>whilelen(L)>=1:
tmp = L.pop()print(tmp)breakelse:print("exit while")9>>>>>>for digit inrange(10):print('the number is: {digit}'.format(digit = digit))breakelse:print("exit for")
the number is:0>>>