下面的是网上看到的其他人的关于跳出多重循环的办法
一,可以插入exception跳出。
class FoundException(Exception): pass
try:
for row,record in enumerate(table):
for columu,field in enumerate(record):
for index,item in enumerate(field):
if item == target:
raise FoundException()
except FoundException:
print ("found at ({0},{1},{2})".format(row,column,index))
else:
print ('not found')
二,就是放在函数体里,用return 语句返回。
def test():
for x in range(9,0,-1):
for y in range(9,-1,-1):
for z in range(9,-1,-1):
s = 100001*x+10010*y+1100*z
s1 = int((round((s**0.5),0))) + 1
for i in range(s1,100,-1):
if s % s1 ==0:
print s,i
return s